IDocumentEvents rewiring question

Discussion created by Gagag on May 2, 2011
I have an extension in which I have implemented IDocumentEvents because I need to keep track of documents being opened and closed and new'ed. Essentially what I am doing is to cache the current mxdocument in the IExtensionConfig.StartUp and wire it up for the IDocumentEvents. Later, in the IDocumentEvents.OpenDocument event, I compare the current document with the cached one. If they are not same, I rewire the current mxdocument for events.

The event wiring happens correctly after the initial wiring, and the OpenDocument does get called when a document is opened. However, the cached document and the current document are found to be the same. As a result, my logic never kicks into action. Obviously I am doing something wrong. Does the OpenDocument get called before the document is opened?Can someone help me out by explaining how to handle document events?