开发者

Background work that perform UI change and modal dialog

开发者 https://www.devze.com 2023-02-16 21:29 出处:网络
I have a C#/WPF application that is going to perform a lot of actions, including UI modifications (it is loading a Macro), but I want to have a modal window with something moving telling to wait.

I have a C#/WPF application that is going to perform a lot of actions, including UI modifications (it is loading a Macro), but I want to have a modal window with something moving telling to wait.

The load macro work 开发者_StackOverflowmust be performed in the main application thread, but how to I print the modal window as it must be non blocked by the macro loading but in the application thread because it is a UI thing.

Currently I put the LoadMacro in an BackgroundWorker in a Application.Current.Dispatcher.Invoke while displaying my waiting dialog. But it is not satisfying because the two fight each other to update the UI.

So how do I do it ?


You don't need to run the background worker from any dispatcher.

Load your modal window and then kick off the background worker having subscribed to it's ProgressChanged event. You can then ReportProgress on the background worker passing anything you like back to update the model window in the UserState property.

http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.progresschanged.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消