-2

I need the following while loop to repeat until the balloontip is clicked. How can I do this?

while(/*Here, I want the loop to end when the Norm.BalloonTipClicked occurs*/)
               {
                   Norm.ShowBalloonTip(10000);
                   System.Threading.Thread.Sleep(10000);
                   `enter code here`
                   System.Threading.Thread.Sleep(60000);
               }

(As you probably realize, 'Norm' refers to the name of the notification icon)

Sumeshk
  • 1,980
  • 20
  • 33
Often Right
  • 427
  • 1
  • 9
  • 22
  • 5
    Why? The `NotifyIcon` has a `Click` event: http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.click(v=vs.110).aspx – Simon Whitehead Jan 16 '14 at 05:00
  • But if I tried using the Click event, it means that I will exit the loop doesn't it? Perhaps to explain things more clearly, the loop you see above is nested in an infinite for loop. – Often Right Jan 17 '14 at 02:56
  • Use a flag of some sort to indicate that you want to continue. Would you like to see what I mean? – Simon Whitehead Jan 17 '14 at 02:59
  • Let me try to explain this in the context of the whole piece of software. I have an overall infinite nested for loop, and this while loop is one loop that sits inside this overall loop. I want this while loop to continue looping (ie the balloontip to keep popping up every minute) until the user clicks on the balloontip, which then triggers the computer to run the next loop. I've continued researching and still can't find anything like this. Does this help? – Often Right Jan 17 '14 at 04:27
  • I am away from my PC at the moment. If you can wait a little while I will clarify with an example. A flag in this context is a boolean variable that is checked every iteration of your loop. – Simon Whitehead Jan 17 '14 at 06:40

1 Answers1

0

Using flags, as suggested by Simon Whitehead, I have been able to solve the problem. By using the below code, everything now works!

 bool for3 = false;
                    for (; ; )
                    {
                        Norm.ShowBalloonTip(10000);
                        System.Threading.Thread.Sleep(10000);
                        Application.DoEvents();
                        if (loopVariable)
                            for3 = true;
                        if (for3) break;
                        System.Threading.Thread.Sleep(60000);

                    }
private static bool loopVariable = false;

  void Norm_BalloonTipClicked(object sender, EventArgs e)
   {
       loopVariable = true;
   }

Thanks to Simon Whitehead for all of his help! It is much appreciated.

Often Right
  • 427
  • 1
  • 9
  • 22