I am creating a C# app that handles Excel applications.
The excel file I am loading are preloaded (as it takes a while to load it due to the file's girth) and then shown when requested by the user.
However, when the user shuts down Windows, Windows sends Session query ended messages to the hidden excel app, forcing a visible "Would you like to save changes to '(EXCEL FILE)'?".
How do I override this behavior and gracefully kill off the excel file?
I've looked into suppressing the save prompt via VBA, but Session Ended messages do not execute this code.
Additionally, I've looked into killing the process by handling my own C# app's Session Query End message, but this is unreliable as it is a race (what app gets the message first, my C# or my hidden excel file)
Edit: By gracefully kill, I mean just kill the process off without prompting the user. I know how to do this when the user chooses to exit my program, I just don't know when to call this routine.
Edit2:
I keep track of instances of Excel in memory using Microsoft.Office.Interop.Excel
Without showing your code it's difficult to tell what you have, however, here is a snippet from my code which works in a similar situation (I think) without a prompt:
Excel.Application xl = new Excel.Application();
xl.Visible = false;
xl.DisplayAlerts = false;
//do something
xl.Quit();
Marshal.ReleaseComObject(xl);
xl = null;
GC.Collect();