异步尝试阻止WPF [英] Async Attempt WPF Blocking
本文介绍了异步尝试阻止WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我学习异步/等待关键字。我看不出什么,我在这里做语法写的吗?
I'm learning about async/await keywords. I can't see what I'm doing wrote here syntactically?
我有以下两种方法:
private async Task<string> PopupAsync()
{
String result;
using (StreamReader reader = File.OpenText(@"C:\temp\JBM_SchedulingModule.xap"))
{
Console.WriteLine("Opened file.");
txtData.Text = "Opened file.";
result = await reader.ReadToEndAsync();
}
return result;
}
和
private async void Button_Click(object sender, RoutedEventArgs e)
{
txtData.Text = await PopupAsync();
}
当我preSS按钮的主UI线程被冻结,我不希望它。试图了解为什么,以及如何解决。
The main UI thread is freezing when I press the button and I don't want it to. Trying to understand why and how to fix.
谢谢!
推荐答案
斯蒂芬是正确的。我想到了。因为它应该是它的工作。为什么它被阻塞的原因是不是因为ReadToEndAsync(),但所花费的时间来填充+加载一个4MB的字符串(从文件)到WPF控件。
Stephen is right. I figured it out. It does work as it's supposed to it. The reason why it was blocking was not because of ReadToEndAsync(), but the time it took to populate + load a 4MB string (from a file) to a WPF control.
这篇关于异步尝试阻止WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文