Hi all!
I would like to suspend a thread and then resume it with the same procedure.
I would expected that this code (you can just cut-and-paste into a new console project) will do the thing, but when i do the Resume() nothing happen!
Why it does not restart the Execute() procedure???![]()
PHP Code:using System;
using System.Threading;
namespace thread
{
public class Class1
{
public static void Main()
{
ThreadedClass t = new ThreadedClass();
t.Start();
Thread.Sleep(10);
t.Suspend();
Console.WriteLine("NOW RESUME!");
t.Resume();
Thread.Sleep(10);
t.Abort();
}
}
public class ThreadedClass
{
private Thread oThread;
public ThreadedClass()
{
oThread = new Thread(new ThreadStart(this.Execute));
}
public void Start()
{
oThread.Start();
}
public void Abort()
{
oThread.Abort();
oThread.Join();
}
public void Suspend()
{
oThread.Suspend();
}
public void Resume()
{
oThread.Resume();
}
private void Execute()
{
do
{
Console.WriteLine(DateTime.Now.ToString() + " - Executing");
}
while (true);
}
}
}





Reply With Quote