1

So, the program displays a balloontip for the first time. If it is clicked, it disappears and the program continues. If it isn't clicked, the balloontip fades out, waits five minutes, then flickers on and off very quickly, freezing the program. Any reasons why?

for (; ; )
{
    Norm.ShowBalloonTip(10000);
    while (DateTime.Now.Subtract(start).Seconds < 10)
    {
        Application.DoEvents();
        if (loopVariable)
            for3 = true;
        if (for3) goto label4;
    }
    while (DateTime.Now.Subtract(start).Minutes < 5)
    {
        Application.DoEvents();
    }
}
Yuck
  • 49,664
  • 13
  • 105
  • 135
Often Right
  • 427
  • 1
  • 9
  • 22
  • 1
    I have to ask, and I am afraid for the answer. Are you seriously using `goto`? You know it's *considered harmful*. – Yuck Feb 16 '14 at 02:30
  • Does your loop ever exit (does `for3` ever become true)? You might want to throw in a Sleep or two. – 500 - Internal Server Error Feb 16 '14 at 02:40
  • @500-InternalServerError Yes, the loop does exit. My main problem is that a routine that works fine the first time works completely differently the second time (the balloontip flickers). – Often Right Feb 16 '14 at 02:54
  • @Yuck: Yes, I know I probably shouldn't be using goto, but the goto label is very close to the goto statement, and it does the job well. – Often Right Feb 16 '14 at 02:55
  • 1
    Using non-standard methods is not doing the job well, otherwise you would not have a flickering baloon tip. There is a lot of other "bad practices" you are doing besides the `goto` (for example I have never seen a situation outside of COM programming where `Application.DoEvents()` was the "correct" thing to do) – Scott Chamberlain Feb 16 '14 at 03:29
  • @ScottChamberlain: could you please suggest an alternate method? Thank you – Often Right Feb 16 '14 at 03:34
  • 1
    Not without seeing a lot more of what the code is doing, usually infinite loops with a `Application.DoEvents()` should be replaced with [some form of Timer](http://msdn.microsoft.com/en-us/magazine/cc164015.aspx) – Scott Chamberlain Feb 16 '14 at 03:36
  • @ScottChamberlain: will do – Often Right Feb 16 '14 at 03:36

0 Answers0