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
You can use AutoResetEvent to signal when your thread is finished.
Check this code snippet: