c# dispatch queues like in objective c

我们两清 提交于 2019-12-03 08:27:34

If all you want is to execute some long-running CPU-intensive code on a background thread, and when it's done, process the result on the UI thread, use Task.Run() in combination with await:

async Task AMethod()
{
    var result = await Task.Run(() => LongRunningWork());
    DoSomethingWithResult(result);
}

The AMethod() is now an async Task method, which means its caller also has to be an async method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!