MonoTouch的 - 线程 [英] MonoTouch - Threading

查看:166
本文介绍了MonoTouch的 - 线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个常见的​​任务是做一些后台线程,做那么当,将结果传递到UI线程,并通知用户。

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:

我可以使用TPL:

var context = TaskScheduler.FromCurrentSynchronizationContext ();

Task.Factory.StartNew (() => {
    DoSomeExpensiveTask();
    return "Hi Mom";
}).ContinueWith (t => { 
    DoSomethingInUI(t.Result);             
}, context);

或更早的线程池:

    ThreadPool.QueueUserWorkItem ((e) => {
          DoSomeExpensiveTask();
      this.InvokeOnMainThread (() => {
             DoSomethingInUI(...);
      });
});



有没有推荐的方法使用MonoTouch的构建iOS应用程序什么时候去?

Is there a recommended way to go when using MonoTouch to build iOS apps?

推荐答案

虽然我更喜欢的任务并行库中的线程池代码库是老年人(在单声道和MonoTouch的),这样​​你就更有可能找到文档它并不太可能创出错误

While I prefer the syntax of Task Parallel Library the ThreadPool code base is older (in both Mono and MonoTouch) so you're more likely to find documentation for it and less likely to hit a bug.

这篇关于MonoTouch的 - 线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆