c# - UWP Windows 10 中的多线程

标签 c# multithreading windows-10 uwp

我正在为 Windows 10 制作 UWP 应用程序。我想在父/默认线程之外的单独线程中执行两个方法,以便我的应用程序可以更快一点。但我在 UWP 中找不到 Thread 类。我有的是Task,但它不像Thread那么简单。

方法如下。

public List<Rootobject> <Method_name>()
private List<string> <Method_name>()

我错过了什么?

最佳答案

您必须使用 Task 而不是 Thread,因为目前不支持 Thread(请参阅开放票 https://github.com/dotnet/corefx/issues/2576 )。创建一个任务有什么不那么容易的?

Task t = Task.Factory.StartNew( () => {
              // Just loop.
              int ctr = 0;
              for (ctr = 0; ctr <= 1000000; ctr++)
              {}
              Console.WriteLine("Finished {0} loop iterations", ctr);
          } );

请参阅微软文档:link 您的方法示例:

// Running the method which returns List<string>
Task<List<string>> result = Task.Factory.StartNew(() => ExpensiveMethod());


public List<string> ExpensiveMethod()
{
    return ...;
}

关于c# - UWP Windows 10 中的多线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38030603/

相关文章:

c# - 用于 Windows 8 开发的 Metro 与 WPF?

c# - 将十进制转换为十六进制

Java 多线程执行受阻

git - 通过 pull 入 SmartGit 删除的文件 - 我可以恢复它们吗 (Windows 10)

visual-studio-2015 - 如何在 Windows 10/Visual Studio 2015 中禁用 F11?

Windows 10 上的 iisreset 错误

c# - 如何将此 linqTOsql 查询转换为 lambda

c# - Asp.NET MVC 是 MVC 还是 MVP?

python - 阻塞 Tkinter 接口(interface),直到线程完成其任务

android - Android AsyncTask 和 realm.executeTransactionAsync 的区别