Author: Charlie Parker
URL: http://snippets.dzone.com/posts/show/4230
// just inherit from the EasyThread class and override the PerformWork method
public class EasyThread: IDisposable
{
Thread WorkerThread;
public EasyThread()
{
if (WorkerThread == null)
WorkerThread = new Thread(new ThreadStart(PerformWork));
}
public void Run()
{
if (WorkerThread.IsAlive == false)
WorkerThread.Start();
if (WorkerThread.ThreadState == ThreadState.Suspended)
WorkerThread.Resume();
}
/// <summary>
/// EasyThread provides a facade to inheriting from a Thread class.
/// Override the perform work method to perform your tasks.
/// </summary>
protected virtual void PerformWork()
{
}
public void Pause()
{
WorkerThread.Suspend();
}
public void Quit()
{
Cleanup();
}
private void Cleanup()
{
WorkerThread.Join(0);
WorkerThread = null;
}
public void Dispose()
{
Cleanup();
}
}











hi,
First of all. Thanks very much for your useful post.
I just came across your blog and wanted to drop you a note telling you how impressed I
was with the information you have posted here.
Please let me introduce you some info related to this post and I hope that it is useful
for .Net community.
There is a good C# resource site, Have alook
http://www.csharptalk.com/2009/09/c-class.html
http://www.csharptalk.com
simi