preventing events to be fired

D

dani

Hi everybody

I have a problem:

Assume I have two shapes and a connector between it which is connected
to both of them.

Now, if I remove just one end of the connector from a shape, I get once
the connectionsDeleted-event to which I listen to. But if I drag the
connector away from both shapes, both connections are deleted and the
event is fired twice.

Now my question: No matter what case happened, I want to launch my
ConnectionsDeleted-EventHandler-Method exactly once. Is it somehow
possible to ignore the second firing of this event so the handler
doesn't get startet again?

thanks

Daniel
 
M

Mark Nelson [MS]

One way to manage this is to postpone execution of any code when handling an
event. When you handle an event, create a task for your program to perform
and put that task into a queue. Then listen for Visio's NoEventsPending
event and execute all the tasks in the queue.

The benefit of this approach is that you can deal with multiple events that
should trigger only a single task for your program. When you get the
ConnectionsDeleted event, check the task queue for an exisiting task related
to connections deleted. If there is none, add a task. Otherwise, do
nothing.

Besides ConnectionsDeleted, this approach works really well for CellChanged,
where there may be dozens of events that fire for each action you want to
take. However, if you do this, do it for all your event handlers to keep
the events and responses in sequence. The primary disadvantage of this
approach is that some Visio events force you to deal with shapes and other
objects right away because they are being deleted. You will not have access
to the object later when processing your queue, so you need to gather all
the information you need immediately and include it in the task info that
you store in the queue.

There may be an example application in the SDK that uses this approach.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top