从 Windows phone 8.1 中的任务调用主线程
Calling main thread from a task in Windows phone 8.1
我有密码
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);
}
}
我想在主线程中调用委托函数。我尝试了 Dispatcher,但没有 Dispatcher Class。我将如何在 windows phone 8.1 sdk
中做到这一点
您可以从应用程序的任何位置访问 CoreWindows 的 Dispatcher,如下所示:
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => {
//call main thread here
});
请记住,调用主线程需要一些时间(在我的诺基亚 Lumia 635 上最多需要半秒)。因此,例如,如果您有循环,请不要在每次迭代中使用 Dispatcher.RunAsync()
。
我有密码
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);
}
}
我想在主线程中调用委托函数。我尝试了 Dispatcher,但没有 Dispatcher Class。我将如何在 windows phone 8.1 sdk
中做到这一点您可以从应用程序的任何位置访问 CoreWindows 的 Dispatcher,如下所示:
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => {
//call main thread here
});
请记住,调用主线程需要一些时间(在我的诺基亚 Lumia 635 上最多需要半秒)。因此,例如,如果您有循环,请不要在每次迭代中使用 Dispatcher.RunAsync()
。