I recently had an issue pop up with some of my code whereby the document/database events I chose to automatically fire off some functionality during drawing saving caused unexpected errors.
Initially, I chose the following logic to hook up my events;
- Upon initialisation, I hooked a DocumentCreated Event called OpenDrawingAction
- OpenDrawingAction then hooked up a BeginSave event to the active database, called OnBeginSave, every time a drawing opened
This worked as expected until an intermittent bug arose. First off, it was noticed that when an autosave occurred, the OnBeginSave functionality always fired twice. This wasn't a big issue until it was noted that if more than one drawing was open, the user switched back and forth between them and more autosaves took place, the OnBeginSave functionality now stopped working completely. I tried to get to the bottom of why the double save occurred during autosaves, and why it seemingly blanked the save event hook-ups, but didn't really get anywhere.
As such, I tried some different event configurations and arrived at the following;
- During initialisation, I still hook up my DocumentCreated event (though removed its BeginSave hook-up), but have added a DocumentLockModeChanged event
- The DocumentLockModeChanged event now replaces the BeginSave functionality though is directed specifically at the QSAVE and SAVE commands when the lock mode is set to Write
This alternative setup means autosave now no longer fires off the save functionality at all (which is good - the extended functionality involves asynchronous calls to doc control databases), and the functionality persists between multiple drawings/autosaves. I'm posting this as a general heads-ups, and to see if anyone could explain what I was doing wrong intially and maybe possible pitfalls with my current approach.
AutoCAD 2011 64bit, C#.NET, VS2010.