In order to avoid duplicate eventhandlers, I did like the following...
Document doc = Application.DocumentManager.MdiActiveDocument; try { doc.BeginDocumentClose -= new DocumentBeginCloseEventHandler(MyEventHandler); } catch { // Do nothing } doc.BeginDocumentClose += new DocumentBeginCloseEventHandler(MyEventHandler);
The above worked greatly with AutoCAD 2007.
But yesterday I migrated my code into AutoCAD 2010 (with Object ARX 2010).
Unfortunately, it seems like AutoCAD 2010 catches before my code catches it.... (Though I am not sure if this is even make sense)
The evidence...
If I ignore this message, everything works great as it was meant to be...
I am just wondering if I could disable(?) this. Or if there is any other effective work around....
Well, I guess I could just have a global boolean value that checks the status of event attachment.
But would this be the only way?
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Thank you everyone~
@matus: Actually, I just tried and got the same message in production (release) mode.
@Alexander
In fact, the above code was simplified one. I will write it in more detail.
[CommandMethod("CreateObject")] public static void CreateObject() { // Creates a global object MyStaticClass.CreateObject(); // When the current document is closing confirm user whether or not to destroy the object // This event handler is required only after CreateObject is called Document doc = Application.DocumentManager.MdiActiveDocument; try { doc.BeginDocumentClose -= new DocumentBeginCloseEventHandler(MyStaticClass.ConfirmDestroyObject); } catch { // Do nothing } doc.BeginDocumentClose += new DocumentBeginCloseEventHandler(MyStaticClass.ConfirmDestroyObject); } public static class MyStaticClass { ... internal static void ConfirmDestroyObject(object sender, DocumentBeginCloseEventArgs e) { Document doc = sender as Document; ... System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show(msg, "Alert", System.Windows.Forms.MessageBoxButtons.OKCancel); if (dr == System.Windows.Forms.DialogResult.OK) { MyStaticClass.DestroyObject(); } else { e.Veto(); } } }
My case... dose look like the static/shared issue...
or maybe am I missing something??
What about checking event handler was added or no?
P.S.: I've not tested your's code.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
This smells like an AutoCAD bug. The same code does not throw any exception on AutoCAD 2014. The only way I see to avoid it is to put a boolean flag somewhere.
If you can make your CreateObject method an instance method, you can store this flag in a field of your command object. You can also use Document.UserData.
Can't find what you're looking for? Ask the community or share your knowledge.