相关疑难解决方法(0)

在后台操作过程中显示模态UI并继续

我有一个运行后台任务的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)

.net c# wpf asynchronous async-await

6
推荐指数
1
解决办法
3219
查看次数

标签 统计

.net ×1

async-await ×1

asynchronous ×1

c# ×1

wpf ×1