none
How multiple coexisting VSTO add-in's handle events RRS feed

  • Question

  • Hi

    We are using a VSTO Add-in for Word which we have implemented in C# and we are also using another VSTO Add-in which is a 3rd party add-in. Both add-ins handle the DocumentOpen event. Is there a way to control the running order of the handlers for each of the add-ins?

    Tuesday, August 30, 2016 2:42 PM

Answers

  • There is no way to control order of notifications of add-ins on the same event. You may look at events chain and try to use an event with happens the last, basically move your logic at the later time, delay it.


    Slava Ivanov

    • Marked as answer by jeeji Wednesday, August 31, 2016 8:49 AM
    Tuesday, August 30, 2016 4:55 PM

All replies

  • There is no way to control order of notifications of add-ins on the same event. You may look at events chain and try to use an event with happens the last, basically move your logic at the later time, delay it.


    Slava Ivanov

    • Marked as answer by jeeji Wednesday, August 31, 2016 8:49 AM
    Tuesday, August 30, 2016 4:55 PM
  • Thanks for the answer.

    Could you explain to me what you mean? Do you mean to handle an event that comes after the DocumentOpen event? In which case, what event would that be. 

    Moreover, do you by any chance know which runs first then: A macro called AutoNew in a newly created document, or the NewDocument event handler in the add-in? The AutoNew macro is located in a dotm file, which when open, creates a new document that runs the AutoNew macro. I just want to make sure that the AutoNew is run before word raises the New Document event?

    Thanks

    Jihad

    Tuesday, August 30, 2016 9:18 PM
  • Hello Jihad,

    Every add-in which subscribed for an event will get notified in some order. There is no particular order and add-in cannot control it.  What can be done is move the logic of your add-in to an event which happen before or after (depend on your needs) event used in another 3rd party add-in. In this case you would guarantee to be called before or after the 3rd party add-in invoked just because it would happen at different time.

    For example you know the 3rd party add-in gets called every time document created and you would like to invoke your logic after that. In this case you would need to look at events happen after document get created, for example document activate or something. The events of the document are described over here: Document events . And for events of the application you may refer to: Application Events (Word) .

     I strongly believe the macro basically yet another add-in which will be activated and get notification in some order like any other add-in. If macro handle document create event and your add-in subscribed to the same event there is no any particular order of notification. "AutoNew" is not an event, this is just the name of macro. Please refer to: Auto Macros . 

    Hope this clarify a bit,


    Slava Ivanov

    Tuesday, August 30, 2016 9:56 PM
  • Hi jeeji,

    According to your description, you could refer to Running a macro automatically when a document is created, opened or closed

    >>>Is there a way to control the running order of the handlers for each of the add-ins?

    This workaround is that you could register the add-ins to "load on demand" rather than to load automatically. Then create an additional add-in the sole purpose of which is to load the other add-ins, in the desired order. 

    For more information, please refer to below link:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/dde5f830-1348-4a91-9a22-de688cbb9e64/change-the-load-order-of-com-addins-in-excel-2003?forum=vsto

    Disclaimer: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Thanks for your understanding.

    Wednesday, August 31, 2016 6:45 AM
  • Thanks David for you interesting reply.

    I am thinking that your solution will work for documents being opened when no instance of Word is running.

    However if there is an instance of Word running  (thus the add-ins have loaded), then opening a document will raise the event DocumentOpen, and I will not be able to control the order of which the add-handle the event. Does that sound reasonable? And if yes, do you have a solution for controlling that order, when the add-ins have loaded?

    Or do you think that the add-ins load order reflects the handling order of the event. So that if add-in1 loads first, then it will be the first to receive the events Word raises?

    Thanks again

    Jihad


    • Edited by jeeji Wednesday, August 31, 2016 8:59 AM
    Wednesday, August 31, 2016 8:55 AM
  • From your conversation i got an idea that may work like in this way, why we make both the Add-Ins Load-On Demand and create a Add-In which can load them as desired (control the order of loading). Anyhow if a Add-In loads after handling of DocumentOpen event by other Add-In will lose it, i think. Then we have to figure out how to raise that event manually.
    Wednesday, August 31, 2016 9:04 AM
  • Thanks. I am pretty sure that DocumentOpen will not be handled by any Add-In if Word is starting up (because none of the add-ins have been loaded). So this will not be a problem. The problem is that if Word has loaded thus all add-ins are loaded, who and in which order will the DocumentOpen event be received the next time a document is opened in that instance of Word?
    Wednesday, August 31, 2016 10:26 AM
  • its soo hard to determine, but you can use visual studio's performance profiler option. Use it on an executable (.exe) which in your case WINWORD.exe. But still you'll get minimum information about the order that the DocumentOpen handler calls for the two Add-Ins, i've tried.
    Wednesday, August 31, 2016 1:59 PM
  • Hello Jihad,

    We worked a lot with the problems of coexistence of add-ins when our customers are complaining on issues caused by our add-in and 3rd party add-ins loaded into application. We chase the idea of loading order and would like to be the last one (in our case) get notified on an event in the line up of add-ins subscribed to this event. Of cause you cannot control what other developers do in the event handler, but you can re-think over what you do when get notified at the event. This was exactly our solution ... we stop chasing the loading roller-coaster and instead think again on our business needs at particular time (event). We moved out some of the logic we relay on at the times when user start interacting with add-in UI, we subscribed on events which happens later, keep track in the singleton class of the add-in to get information on what we've done and what needs to be.

    May be this solution will not work out for your business needs, but it was working for us in most cases. By the way we still sometime have some compatibility issues with 3rd party add-ins, but those are unique cases we trying to work out or live with them.

    Sorry, this doesn't answer your original question, just a suggestion.

    Best regards,


    Slava Ivanov

    Wednesday, August 31, 2016 4:01 PM