c# - 从 Windows Phone 8.1 中的任务调用主线程

标签 c# multithreading windows-phone-8

我有一个代码

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/

相关文章:

C#接口(interface)属性实现

c# - 如何在 .NET 中装饰(时间)任务?

multithreading - 如何使用 Condvar 来限制多线程?

c# - 当 web.config 设置为 Forms 时,AuthenticationSection.Mode 返回 Windows

c# - 为什么在更新面板中找不到控件

c++ - 大型读写器缓冲机制-高频率数据C++

c# - 通过 Tasks C# 动态搜索中断

c# - Windows 手机 8 : C# XAML how to detect shape collisions

c# - Windows Phone 8.1 LongListSelector 按钮问题

windows-phone-8 - Windows后台任务API异步函数问题