My MvvmCross based desktop application (Windows/WPF + MacOS/Cocoa) creates some temporary files during its normal operation.
The files are created within the async command and deleted before the command ends.
However, because the command is async, the user can close the application before the command finishes by simply clicking the red cross in the main window. In this case the command will not complete its work and the temporary files will not be cleaned.
The application consists of a single View (derived from MvxWpfView) and a corresponding ViewModel. The TipCalc sample (https://github.com/MvvmCross/MvvmCross-Samples/tree/master/TipCalc) can be used as a starting point.
I need to somehow handle the closing of the application and wait for all async operations to finish.
What I have tried so far (class names given as in the TipCalc sample mentioned above):
- implement
IDisposableandIAsyncDisposablefor view modelTipViewModeland viewTipView.Dispose & DisposeAsyncjust not called at all. - override
ViewDestroyin theTipViewModelview model - it is also not called. - subscribe to the
TipView.Unloadevent inside theTipViewitself - event handler not called. - checked for relevant methods to overload or implement into the
MvxWpfSetupandIMvxAppStart- nothing relevant found. - tried to handle
Window.Closeevent on theWindowlevel then transfer the call into theView(MvxWpfView) orViewModel, but could not find the normal way to do everything synchronously or with correct waiting of the async operations.
So, how do I handle the app close and clean up my temporary files?