If you add an event handler during the document created event, you should remove it when the Document to be destroyed event takes place.
Sorry, that's not true.
Events that are members of the Document class are fired by the Document, only as long as it exists. Once a document is destroyed, all events and the handlers added to them are destroyed as well, and so after the document is destroyed, those events will never fire.
It's not necessary to remove handlers for document events if you want them to handle the events for the life of the document.
This begs a question:
If you can add an event handler to an open document and leave it there for the life of the document,
is there any benefit to removing event handlers from a document when the handler is not in use?
My Example: When my App initializes,
I add "Document.CommandWillStart += new CommandEventHandler(Document_CommandWillStart);" to all open documents in AutoCAD
and to any newly created documents during the session.
Then I check for "ClassicGroup" command in my callback for "CommandWIllStart"
and if "ClassicGroup" is the command, I add more event handlers (CommandCancelled, CommandEnded and CommandFailed) to the MDIActiveDocument.
When "ClassicGroup" is Ended/Cancelled/Failed, I do my work accordingly in the CommandEnded/Cancelled/Failed callback and I also remove "-=" the CommandCancelled, CommandEnded and CommandFailed handlers from the MDIActiveDocument.
I have been under the impression that removing the unused handlers was to avoid memory issues during the session.
Do I really have to remove the document event handlers at all?
TIA