Joetjah
Joetjah

Reputation: 6132

Shutting down WPF application with databinding and threading

I'm trying to shut down my application properly. My application uses databinding, accesses a database a few times and probably has some innate threats running as well.

Since Application.Current.Shutdown() doesn't close everything in this case, I looked at Application.Current.Dispatcher.BeginInvokeShutdown().

BeginInvokeShutdown() needs a System.Windows.Threading.DispatcherPriority argument. This can be:

Now, say my application only gets closed when something went wrong. That'd mean nothing has to be completed by the application, just a raw shutdown so the user can restart the application. Am I correct to say I'd have to give Inactive as argument? Is it true if I give Send as argument, everything is finished before completely shutting down?

Upvotes: 3

Views: 337

Answers (1)

JRoughan
JRoughan

Reputation: 1655

Application.Current.Shutdown() should work in your case as long as your threads are background threads. How are they being created? If you're just newing up a Thread object you should be able to set the IsBackground property to true. If they need to be foreground threads you'll need to manually stop the loop(s) when shutting down.

As for your actual question from what I understand BeginInvokeShutdown will still process everything in the UI thread queue but will not accept any more actions. The priority just seems to be similar to a normal thread priority setting as it relates to CPU usage with the extra ability of ending the invoked task to the front of the processing queue.

Upvotes: 1

Related Questions