When i want to run Long Operation i want to show model dialog window (Wait Window)
I want to display this Wait Window in different Thread as ShowDialog()
Before entering into Long Running Operation, i will display Model Dialog Window
After done with Long Running Operation, i will close this Model Dialog Window
I know instead of creating Window in another Thread, we can simply move long Running Code in another Thread but impact of this in my code is heavy.
Please suggest me a solution for this
I would suggest you to avoid such WinForms-smell solutions like ShowDialog()
calls.
Take a look at the out of the box WPF ToolKit BusyIndicator it alows leverage a power and flexibility of WPF and XAML.
BusyIndicator makes it easy to let the user know when an application is busy. Simply wrap the relevant content in an instance of the BusyIndicator control and toggle its IsBusy property to True during any long-running process.
It allows build custom wait windows, for instance:
You have full control of UI layout and can define your own DataTemplate:
<extToolkit:BusyIndicator IsBusy="True" DisplayAfter="0">
<extToolkit:BusyIndicator.BusyContentTemplate>
<DataTemplate>
....
See Extended WPF Toolkit BusyIndicator for more examples and download.
First of all, my advice is to remove the 'long running operation' from the UI thread.
That being said, here's an article discussing what you try to do.
http://eprystupa.wordpress.com/2008/07/28/running-wpf-application-with-multiple-ui-threads/
The following code is presented:
Thread thread = new Thread(() =>
{
Window1 w = new Window1();
w.Show();
w.Closed += (sender2, e2) =>
w.Dispatcher.InvokeShutdown();
System.Windows.Threading.Dispatcher.Run();
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
You create a new Dispatcher that will handle UI messages and events on the new thread. The attached Closed event handler ensures that the created dispatcher does not continue running after you close your form, thus keeping the application from running 'forever'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With