简体   繁体   中英

Custom Microsoft Word .NET VSTO Add-In breaks after an hour of idling

We have a custom Ribbon built to work with Microsoft Word that utilizes Word's DocumentBeforeSave event to execute some business logic every time the user saves the document, binding and declarations look like this:

//This binding is executed on Ribbon load:
Globals.ThisAddIn.Application.DocumentBeforeSave += Application_DocumentBeforeSave;


//This is the method we bind to the event:
void Application_DocumentBeforeSave(Word.Document Doc, ref bool SaveAsUI, ref bool Cancel)
{
     // Business logic here
}

This works perfectly fine, and the Doc object being passed to our method contains all the content and relevant data (notes, path, name, etc...) However if the application is left to idle for about an hour the function no longer receives the data as expected.

Results of adding logs and tracking the process at failure shows the following:

  1. The Application_DocumentBeforeSave function is still properly bound to the correct event and is being fired every time the user saves
  2. The Word.Document Doc variable being passed to Application_DocumentBeforeSave however does not contain the content of the active document or any of the relevant data. Debugging the Doc.Path member returns the following path: C:\Users\<USER>\AppData\Roaming\Microsoft\Word instead of the expected path of the open document.

Is this a known issue of VSTO AddIns timing out or is there a way to prevent this from happening?

Is this a known issue of VSTO AddIns timing out or is there a way to prevent this from happening?

Nope. The Application.DocumentBeforeSave event is fired before any open document is saved. That means it is fired for all documents opened in Word. For example, Word can be automated from another applications and etc.

It is not clear what code is used in the event handler itself. And it would great to check other add-ins and code that could handle the same event as well. They can release the document instance, for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM