.NET Threading : How to wait for other thread to finish some task

Posted by Alex Ilyin on Stack Overflow See other posts from Stack Overflow or by Alex Ilyin
Published on 2010-05-18T05:19:35Z Indexed on 2010/05/18 5:20 UTC
Read the original article Hit count: 165

Filed under:
|

Assume I have method void SomeMethod(Action callback) This method does some work in background thread and then invokes callback. The question is - how to block current thread until callback is called ?

There is an example

bool finished = false;
SomeMethod(delegate{
 finished = true;
});
while(!finished)
  Thread.Sleep();

But I'm sure there should be better way

© Stack Overflow or respective owner

Related posts about .NET

Related posts about multithreading