Showing busy indicator on a STA thread

后端 未结 1 496
独厮守ぢ
独厮守ぢ 2021-01-22 22:25

I have a long operation wehre I\'d like to show the Extended Toolkits busy indicator. I made a previous post about this and it was fixed Wpf Extended toolkit BusyIndicator not s

相关标签:
1条回答
  • 2021-01-22 22:40

    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();
    
    0 讨论(0)
提交回复
热议问题