You might want to explore Tasks , which are new to .NET 4.0.
This allows you to run an asynchronous operation, but also gives you an easy way to see if it was done or not later.
var task = Task.Factory.StartNew(() => DoSomeWork());
It will start DoSomeWork () and continue without waiting to continue with another processing. When you get to the point that you don't want to process more until your asynchronous task completes, you can call:
task.Wait();
Which will wait there until the task is completed. If you want to return the result from the task, you can do this:
var task = Task.Factory.StartNew(() => { Thread.Sleep(3000); return "dummy value"; }); Console.WriteLine(task.Result);
Call the task.Result function before receiving the result.
Here's a tutorial on tasks in more detail: http://www.codethinked.com/net-40-and-systemthreadingtasks
source share