Ian*_*ink 6 c# xamarin.ios threadpool task-parallel-library ios
一个常见的任务是在后台线程中执行某些操作,然后在完成后将结果传递给UI线程并通知用户.
我知道有两种常见的方法:
我可以使用TPL:
var context = TaskScheduler.FromCurrentSynchronizationContext ();
Task.Factory.StartNew (() => {
DoSomeExpensiveTask();
return "Hi Mom";
}).ContinueWith (t => {
DoSomethingInUI(t.Result);
}, context);
Run Code Online (Sandbox Code Playgroud)
或旧的ThreadPool:
ThreadPool.QueueUserWorkItem ((e) => {
DoSomeExpensiveTask();
this.InvokeOnMainThread (() => {
DoSomethingInUI(...);
});
});
Run Code Online (Sandbox Code Playgroud)
使用MonoTouch构建iOS应用程序时是否有推荐的方法?
| 归档时间: |
|
| 查看次数: |
5745 次 |
| 最近记录: |