我有一个运行后台任务的WPF应用程序使用async/await.任务是在进展时更新应用程序的状态UI.在此过程中,如果满足某个条件,我需要显示一个模态窗口,让用户知道此类事件,然后继续处理,现在还更新该模态窗口的状态UI.
这是我想要实现的草图版本:
async Task AsyncWork(int n, CancellationToken token)
{
// prepare the modal UI window
var modalUI = new Window();
modalUI.Width = 300; modalUI.Height = 200;
modalUI.Content = new TextBox();
using (var client = new HttpClient())
{
// main loop
for (var i = 0; i < n; i++)
{
token.ThrowIfCancellationRequested();
// do the next step of async process
var data = await client.GetStringAsync("http://www.bing.com/search?q=item" + i);
// update the main window status
var info = "#" + i …Run Code Online (Sandbox Code Playgroud)