views:

42

answers:

3

A portion of my program requires a "flag" retrieval, that is I am fetching a value that is either True or False, and based on this return value two things could follow.

1) The flag is true, aka "go ahead", and I retrieve data from a database.

2) The flag is false, and I want to prevent the data from being retrieved.

Now, this check has to be performed before any function that would call upon the database in question. I decided to implement this check in the form of an event handler attached to GUI objects that would trigger this data inquiry.

This check event handler is called first upon necessary events, and my question is:

How do I stop subsequent event handlers from firing if the FIRST event handler (my flag checker) comes up FALSE?

Thanks

A: 

You can't stop the execution of the events. Simply put the check in front of the data query function, so it gets called whenever data is requested.

Femaref
There are a LOT of places which would need this check, which is why I leaned toward adding the events to minimize copy/paste.Is there another way to accomplish what I am trying to do without adding this check in the many places they need to be placed?Thanks!
gjk
You just need to insert an operation in the middle. If you had a class that manages the database update, it could have an on click event handler as well as an OnDatabaseUpdate event. When a control is clicked, it can do the validation and selectively fire the OnDatabaseUpdate event. Is this what you are trying to accomplish?
Scott P
A: 

It sounds like what you're probably looking for is more along the lines of a mutex than a flag. I don't believe you can explicitly define the order of handled events.

TreDubZedd
+2  A: 

Your design has a problem in depending upon the event mechanism. You actually have no guarantee that the first handler will get called prior to the others. So, even if you could fire one and not the other events, you could not depend upon the order in which they are called.

You will need to do the check prior to firing the event.

Scott P
+1 for nondeterministic firing of multicast delegate explanation
Marc