Arun Kurmi

Arun Kurmi

  • NA
  • 104
  • 103.8k

Thread Suspending

Jul 7 2013 9:49 AM
this is Error in my code---
Thread_Suspend.cs(12,1): warning CS0618: 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated.  Please use other classes in
        System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.
        http://go.microsoft.com/fwlink/?linkid=14202'


And my code are:

using System;
using System.Threading;
namespace my{
class program{
static Thread th;
static void Main(){
th=new Thread(MyFunction);
th.Name="My Thread";
Console.WriteLine("Threading start......");
th.Start();
Thread.Sleep(10000);
th.Suspend();
Console.WriteLine("Now Thread Suspended.");
}
static void MyFunction(){
int i;
for(i=1;i<25;i++)
{
int time=new Random().Next(25,50);
Console.WriteLine("Thread {0} display and then thread suspend for {1}  milliseconds",th.Name,time.ToString());
Thread.Sleep(time);
}
}
}
}


Answers (6)