locked
ENVDTE DocumentSaved event handler not always getting called in host appliction RRS feed

  • Question

  • I'm using the EVNDTE automation object to load and interact with an instance of Visual Studio. Many interations seem to be working fine - I can get the VS IDE to come up, open the desired solution and file, etc.) In my host (calling) application, I've created a DocumentSaved event handler for a specific document in the opened Visual Studio project. The first time I do a save of that document in the Visual Studio instance, my handler always seems to get called and gets called everytime thereafter as long as my Visual Studio instances has focus. As soon as I either minimize it (and bring it back up) or even just switch to another App and back to the Visual Studio instance, my the handler in my host app will no longer get called when I do a save in Visual Studio on the give document. Why won't my handler continue to get called?
    Monday, March 8, 2010 7:04 PM

Answers

  • Through some other related entries, I found the answer to my issue. It had nothing to do with the handler not getting set due to timing. This was an erroneous guess based on some initial observations. The problem is that I'd declared my DocumentEvents variable (to which I added an a new instance of the _dispDocumentEvents_DocumentSavedEventHandler) as a local variable in the scope of the method that was adding the handler. When this went out of scope, it was subject to garbage collection. It was then not long before the event handler in my app was no longer getting called. When I declared the variable at the class level, my handler was consistently called. 
    Monday, March 8, 2010 9:53 PM