When Thread is over

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I created a new thread from a method. I wnat to know when this thread
ended. How can I do that?

public void DoWork()
{
}

public void main()
{
Thread a = new thread( DoWork );
}
 
static void Main(string[] args)
{
ManualResetEvent manualEvent = new ManualResetEvent(false);
Thread t1 = new Thread(new ParameterizedThreadStart(Foo));
t1.Start(manualEvent);
WaitHandle.WaitAll(new WaitHandle[] {manualEvent});
Console.WriteLine("Thread Method Completed");
}
static void Foo(object manaulEvent)
{
Thread.Sleep(5000);
ManualResetEvent manual = (ManualResetEvent)manaulEvent;
manual.Set();
}
 
Roby Eisenbraun Martins
I created a new thread from a method. I wnat to know when this thread
ended. How can I do that?

public void DoWork()
{
}

public void main()
{
Thread a = new thread( DoWork );
}

The simplest solution is to call something other than DoWork:

public void DoWorkThenNotify()
{
DoWork();
ThreadFinished();
}

Thread a = new Thread (DoWorkThenNotify);
....
 
Back
Top