Hi! I have several methods of different importance that I’d like to call
asynchronously from Main(). I am going to span these threads but will have to
implement some kind of a mechanism to wait until ALL of them finish. I’ve
seen some code on MSDN that simply puts thread to sleep (Thread.Sleep(1000)).
While it’s acceptable in some cases, I think sleeping is dirty. 1st and
foremost, I do not know how much time a background thread is going to take,
so I’d have to give a rather large number of milliseconds to wait for all
threads to finish. 2nd, I hate writing my own loop where I perform periodic
checks.
So, here’s my question:
Is there a way to invoke a method asynchronously in such a way that I’ll be
notified when it’s finished? Is there anything built-in in .NET ? What
classes? Any thread monitors out there? Is there a way to find out when all
threads are finished ?
Any suggestions/links/code samples/pseudo code are greatly appreciated.
Thank you in advance,