thread resume with out using sleep method
-
hi i suspend a thread now i have to resume that thread but with out using sleep method the code is below using System; using System.Threading; using System.Collections.Generic; using System.Linq; using System.Text; namespace threadsuspend { public class myclass { public void method() { for (int i = 1; i <= 10; i++) { Console.WriteLine(Thread.CurrentThread.Name + "=" + i); if (i == 5) { Console.WriteLine(Thread.CurrentThread.Name +" is going to suspend"); Thread.CurrentThread.Suspend(); } Thread.CurrentThread.Resume(); } } } class Program { static void Main(string[] args) { myclass mc = new myclass(); Thread thr1 = new Thread(new ThreadStart(mc.method)); Thread thr2 = new Thread(new ThreadStart(mc.method)); thr1.Start(); thr2.Start(); thr1.Name = "ntr"; thr2.Name = "anr"; Console.ReadLine(); } } } please help me out thanks to you
j somasekhar
-
hi i suspend a thread now i have to resume that thread but with out using sleep method the code is below using System; using System.Threading; using System.Collections.Generic; using System.Linq; using System.Text; namespace threadsuspend { public class myclass { public void method() { for (int i = 1; i <= 10; i++) { Console.WriteLine(Thread.CurrentThread.Name + "=" + i); if (i == 5) { Console.WriteLine(Thread.CurrentThread.Name +" is going to suspend"); Thread.CurrentThread.Suspend(); } Thread.CurrentThread.Resume(); } } } class Program { static void Main(string[] args) { myclass mc = new myclass(); Thread thr1 = new Thread(new ThreadStart(mc.method)); Thread thr2 = new Thread(new ThreadStart(mc.method)); thr1.Start(); thr2.Start(); thr1.Name = "ntr"; thr2.Name = "anr"; Console.ReadLine(); } } } please help me out thanks to you
j somasekhar
Another thread would have to resume a suspended thread. Regardless, you shouldn't be using those methods anyway - they aren't only deprecated, they're marked obsolete. What are you trying to do? Surely you can use proper synchronization objects?
Mark Salsbery :java:
-
hi i suspend a thread now i have to resume that thread but with out using sleep method the code is below using System; using System.Threading; using System.Collections.Generic; using System.Linq; using System.Text; namespace threadsuspend { public class myclass { public void method() { for (int i = 1; i <= 10; i++) { Console.WriteLine(Thread.CurrentThread.Name + "=" + i); if (i == 5) { Console.WriteLine(Thread.CurrentThread.Name +" is going to suspend"); Thread.CurrentThread.Suspend(); } Thread.CurrentThread.Resume(); } } } class Program { static void Main(string[] args) { myclass mc = new myclass(); Thread thr1 = new Thread(new ThreadStart(mc.method)); Thread thr2 = new Thread(new ThreadStart(mc.method)); thr1.Start(); thr2.Start(); thr1.Name = "ntr"; thr2.Name = "anr"; Console.ReadLine(); } } } please help me out thanks to you
j somasekhar
Hi, please keep your code nicely formatted, using PRE[^] tags does that for you. Probably the only time it makes sense for a thread to suspend itself, is when another thread is going to resume it. A suspended thread cannot resume itself, it is dead and buried for all intents and purposes, i.e.
Thread.CurrentThread.Resume();
is nonsense. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum