Use Manualreset Event or AutoResetEvent to notify the completion.
Roby Eisenbraun Martins - 11 Jan 2006 15:00 GMT
Hi Naveen,
Where are this events?
> Use Manualreset Event or AutoResetEvent to notify the completion.
Naveen - 11 Jan 2006 15:19 GMT
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
<RobyEisenbraunMartins@discussions.microsoft.com> wrote:
> I created a new thread from a method. I wnat to know when this thread
> ended. How can I do that?
[quoted text clipped - 7 lines]
> 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);
...

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too