I'm writing a class library (for .Net Framework 4.7.2) that has methods that involve flushing a file. This flushing should be done in response to direct method calls, but also if the calling application exits early.
If I was writing code within a WinForms application, I could use
System.Windows.Forms.Application.ApplicationExit += FlushHandler;
to add a handler to the ApplicationExit event and
System.Windows.Forms.Application.ApplicationExit -= FlushHandler;
to remove that handler.
Within a class library, I receive the message:
The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
How can I do something similar to the above within a class library, where the application exit event to handle is the closing of the calling WinForms application?