Showing busy indicator on a STA thread

谁都会走 提交于 2019-12-02 04:35:28

There are multiple approaches:

1) Async binding, it's not recommended, but it is there. You can run long running task in property getter, framework will prevent UI from blocking, when it is finished - UI will get updated.

2) Use BackgroundWorker or Task/Thread to run code, but invoke it into UI thread. In your example:

Dispatcher.InvokeAsync(() => _canvas.Children.Add(p));

3) You can block UI thread of main window completely, no problems. But to indicate about its being busy you can create window in another thread and show there busy status (run animations, etc):

        var thread = new Thread(() =>
        {
            var window = new SomeWindow();
            window.ShowDialog();
        });
        thread.SetApartmentState(ApartmentState.STA);
        thread.IsBackground = true;
        thread.Start();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!