我正在为 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/