My project has a string setting named inHour, and in the main form the user is able to change that string, which is a specific hour and minute formatted this way: hh:mm tt.
Now, let's say I have changed the default hour to 4:50 p.m. When real time reaches that string (by using DateTime.Now.ToString("hh:mm tt") == inHour), a ballontip is shown in the system tray(by using notifyIcon).
So, the comparing time condition is inside a thread that is started at the FormLoad. If time reaches 4:50 p.m. the balloontip shows but it stays visible because the thread has not stopped.
I tried declaring an int set to 0, then set it as i++, so I used a while condition, checking that while int i is not equal to 0 it will check if it is time to show the balloontip but if I set then i to 0 the thread will not continue and if I change the hour to test again it will not work because i is equal to 0 and has not set to infinite again.
So how can I find a way to check for time, show balloontip and start again all the process?
Thanks in advance , CCB
Instead of checking in a loop and tying up an entire thread, it's much more efficient to use a
Timer
that fires at the correct time. This question basically answers your question and has all the relevant information you need.