If you're on .Net 4.0, you can use Tasks and Continuations to wrap your data access. E.g.
var context = TaskScheduler.FromCurrentSynchronizationContext();
var task = Task.Factory.StartNew(() =>
{
DataTable data = SomeSortOfDatacontext.GetOrders();
return data;
});
task.ContinueWith(data =>
{
DataTable data = data.Result;
foreach(Row row in data.Rows)
{
}
},
System.Threading.CancellationToken.None,
TaskContinuationOptions.OnlyOnRanToCompletion, context);
The good thing about Tasks is that it automatically handles marshalling to the UI thread by providing a
SynchronizationContext
Otherwise, you could just use the
ThreadPool[
^] or
IAsyncResult[
^]
Lots of options available to achieve this :)