Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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
Posted

1 solution

You can use timed display instead of showing in thread every time:
C#
var icon = new NotifyIcon();
icon.ShowBalloonTip(1000, "Balloon title", "Balloon text", ToolTipIcon.None)
 
Share this answer
 
v2
Comments
ChrisCreateBoss 11-Aug-15 16:53pm    
Yes I know that but, I need either a thread or a timer to put that method inside because I need to check for the actual time and if it matches with my setting, the balloon should show.
sreeyush sudhakaran 12-Aug-15 0:15am    
I think timer is the best option
ChrisCreateBoss 12-Aug-15 16:25pm    
How should I make it work?
sreeyush sudhakaran 13-Aug-15 1:07am    
For help you need to share some part of code with explanation
ChrisCreateBoss 13-Aug-15 23:46pm    
Same thing you wrote in your answer but inside an if condition saying if (datetime.now.tostring("hh:mm tt") == "4:00 p.m.")... showballoontip();. Just that inside a timer with 1000ms as interval. And sorry about the bad code formatting, but I'm not able now to see visual studio and write exactly the same code. But that is basically what I have written until now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900