I have a prog with a palette I want to update when the active drawing changes.
I was using DocumentBecameCurrent event, but that was firing multiple times.
I changes to DocumentActivated, and have code in the callback to tell me it ran, like:
ed.WriteMessage("File " + activeDoc.Name + " is current.");
So when I have 3 docs open, and start switching windows, I am seeing it randomly repeat the message more than once.
I cannot see a pattern, it is not consistent for a drawing or sequence of change.
I set a break point in the callback, and it alsways only runs once.
Also, I track the activedoc as mentioned here by TT:
http://www.theswamp.org/index.php?topic=41206.msg465080#msg465080
so I am thinking there is something going on with the writemessage method.
I am seeing no other effects telling me I have fooled myself, and the callback is running more than once per switch.
any thoughts here?
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
I even added a:
MessageBox.Show("switched");
to the callback, it always only fires once.
I am used to lisp where it will princ a message, then also echo that as a function return, but I am seeing it echo 3 and four times.
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
It's risky to perform actions which might affect or depend on a stable document manager state *while* the document manager is changing active documents. Not that WriteMessage won't work in this case, just that you can't reliably predict which document the editor will send the message to. It's almost always better to send diagnostic output to your debugger and observe it in the debugger output in order to limit the risk of diagnostic code changing how the debuggee behaves.
I guess I find it interesting the event only happens once, yet the text gets echo'ed more than once, sometimes three times, to the same doc.
I do still want to tell the user my prog caught the doc switch, maybe I just let it repeat itself randomly.
Sounds like you agree I am not tricking myself as far as event only happening once so that's good to hear!
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
If you must display a message, I would at least send it directly to a specific document, thereby bypassing the editor while the document manager state is in flux. Better would be to use some other method of feedback that doesn't involve a document.
Can't find what you're looking for? Ask the community or share your knowledge.