我有一个代码
async Task<String> RunAsync()
{
using(var client = new HttpClient())
{
// Doing some Work without blocking UI.
// Here i want to call my main thread delegate function
del(jsonString);
}
}
我想在主线程中调用委托(delegate)函数。我尝试了调度程序,但没有调度程序类。我该如何在 Windows Phone 8.1 sdk 中做到这一点
最佳答案
您可以从应用程序中的任何位置访问 CoreWindows 的调度程序,如下所示:
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => {
//call main thread here
});
请记住,调用主线程需要一些时间(在我的诺基亚 Lumia 635 上最多需要半秒)。因此,如果您有循环,请不要在每次迭代中使用 Dispatcher.RunAsync()
。
关于c# - 从 Windows Phone 8.1 中的任务调用主线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36052382/