1

I have an event that fires 6 times and I want my pop up appears only once and not 6 times. I tried to use a flag but I can not reset it from the same event. I tried to compare values but didn't work as I have the same result all the times. Any ideas ?

2
  • 1
    Please show some code! Have you added the event-handler multiple times? Commented Mar 12, 2013 at 11:09
  • What kind of event you are trying to handle? Why you need to notify user only once if event continue happening? Commented Mar 12, 2013 at 11:16

2 Answers 2

2

I assume this is in a winforms app that is single-threaded: you could use a static boolean variable 'EventReceived' that you set to true in the first event after showing the popup; as long as 'EventReceived' is true don't show the popup again; and set 'EventReceived' back to false if the popup is closed.

Of course, the question is, why do you receive the event multiple times. Maybe you can avoid this or deal with it differently - but then you have to give us more information.

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately not because it fires from external application, Event Received do you have an example ? thank you in advance
In your windows forms, somewhere put a public static boolean called EventReceived. In your event handler, if EventReceived == false, show popup and set EventReceived to true. If your popup is closed, set EventReceived to false.
1

Try with a static flag variable. Then you can reset the flag from the same event. At the first time application execute the onEvent code segment you need to mark the flag. In the inEvent code segment you can include your operation and before reach to that part of code you must check your flag. (via if clause). If you need to reset your flag after 6 times you can maintain a counter variable and by the counter value you can calculate in which firing cycle you are in. When the counter reach to 6 you can reset your flag variable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.