Method TryShutDownAsync
TryShutDownAsync()
Shuts down the navigator by releasing all views and view model resources. Returns false if shutdown, navigation or busy tasks are in progress, dialogs are showing, or any view models are preventing navigating away from the current view; otherwise returns true after successfully shutting down.
Declaration
Task<bool> TryShutDownAsync()
Returns
| Type | Description |
|---|---|
| Task<bool> |
Remarks
This method should only be called when the navigator is no longer needed (e.g. when the window hosting it is being closed) to ensure that all resources are properly released. This is important in multi-window applications to prevent memory leaks but is not strictly necessary in single-window applications since all resources should be released when the application exits. Navigating or showing dialogs is blocked after the shutdown completes and attempting to do so will result in an InvalidOperationException being thrown.
It may still be beneficial to call this method in single-window applications when the window should be prevented from being closed when dialogs are showing or navigating away from the current view is blocked by a view model (e.g. if the user has unsaved changes). The navigator queries active view models to see if they allow navigating away by calling OnNavigatingAwayAsync(NavigatingArgs).
If the shutdown process is aborted and the method returns false then closing the window should be cancelled.