A common task is to do something in the background thread, then when done, pass the results to the UI thread and inform the user.
I understand there are two common ways:
I can use the TPL:
var context = TaskScheduler.FromCurrentSynchronizationContext ();
Task.Factory.StartNew (() => {
DoSomeExpensiveTask();
return "Hi Mom";
}).ContinueWith (t => {
DoSomethingInUI(t.Result);
}, context);
Or the Older ThreadPool:
ThreadPool.QueueUserWorkItem ((e) => {
DoSomeExpensiveTask();
this.InvokeOnMainThread (() => {
DoSomethingInUI(...);
});
});
Is there a recommended way to go when using MonoTouch to build iOS apps?