I'm working on an Outlook Plugin that read mail body and save it to pdf.

As Outlook doesn't permit to directly save to pdf, i'm saving to word format and use Word with interop to convert it to pdf.

I open Word with these lines

 var WordInstance = new Word.Application();
 WordInstance.Visible = false;
 WordInstance.ScreenUpdating = false;
 WordInstance.NormalTemplate.Saved = true;

Directly after the conversion, i close Word using these lines

WordInstance.Quit(ref oMissing, ref oMissing, ref oMissing);
Marshal.ReleaseComObject(instance);

But sometimes after rebooting my computer i see Word opening with the doc file and after investigation i found that it appear when i close outlook before the end of the conversion.

As described in this Microsoft documentation, it's not possible to detect Outlook closing so i can't quit my Word instance here.

Is there anyway to close child interop app instances when closing the VSTO host app ? Or anyway to detect and quit word before outlook shutdown ? Or just prevent Word from reopening on Windows restart ?

1 Answers

0
Dmitry Streblechenko On

Use Application.Quit event. You can also use Explorer.Close and Inspector.Close events - when all Outlook windows are closed (i.e. Application.Inspectors.Count == 0 and Application.Explorers.Count == 0), Outlook exits.