Reputation: 6132
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:
Invalid
- The enumeration value is -1. This is an invalid priority.Inactive
- The enumeration value is 0. Operations are not processed.SystemIdle
- The enumeration value is 1. Operations are processed when the system is idle.ApplicationIdle
- The enumeration value is 2. Operations are processed when the application is idle.ContextIdle
- The enumeration value is 3. Operations are processed after background operations have completed.Background
- The enumeration value is 4. Operations are processed after all other non-idle operations are completed.Input
- The enumeration value is 5. Operations are processed at the same priority as input.Loaded
- The enumeration value is 6. Operations are processed when layout and render has finished but just before items at input priority are serviced. Specifically this is used when raising the Loaded event.Render
- The enumeration value is 7. Operations processed at the same priority as rendering.DataBind
- The enumeration value is 8. Operations are processed at the same priority as data binding.Normal
- The enumeration value is 9. Operations are processed at normal priority. This is the typical application priority.Send
- The enumeration value is 10. Operations are processed before other asynchronous operations. This is the highest priority. 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
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