简体   繁体   English

Windows应用商店中的System.Threading.Thread替换

[英]System.Threading.Thread replacement in windows store apps

Is it right that 'System.Threading.Thread' douesn't exist in Windows Store Apps? Windows Store Apps中不存在“ System.Threading.Thread”是正确的吗? And if it is, what is the replacement (I want to run a function in the background so the UI douesn't freez while calculating something). 如果是的话,是什么替代品(我想在后台运行一个函数,以便UI在计算某些内容时不会冻结)。 Language is C# and XAML for the UI. UI的语言是C#和XAML。

Use Task.Run or Task.Factory.StartNew 使用Task.RunTask.Factory.StartNew

private void BackgroundWork() { ... }

public async Task DoUsefulWorkAsync()
{
    // Do useful work
    // Start Background Job
    Task backgroundWorkTask = Task.Run(() => BackgroundWork());

    // Do more useful work

    // Wait async for BackgroundWork to complete
    // It won't block the UI thread that we're running on
    await backgroundWorkTask;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM