I want to write a simple program in c# winforms, that shows a notifications to users (in task bar windows 7 or 10) in a constant time (for example in 13:00 and 21:00).
How can I do that?
I want to write a simple program in c# winforms, that shows a notifications to users (in task bar windows 7 or 10) in a constant time (for example in 13:00 and 21:00).
How can I do that?
Basically if DateTime.Now
(current hour) equals a specific hour, show the notify icon.
You should run this code inside of a timer/task.
if (DateTime.Now.Hour == 13 && DateTime.Now.Minute == 00 || DateTime.Now.Hour == 21 && DateTime.Now.Minute == 00)
{
var notification = new System.Windows.Forms.NotifyIcon()
{
Visible = true,
Icon = System.Drawing.SystemIcons.Information,
BalloonTipText = "This is my notify icon",
};
notification.ShowBalloonTip(1000);
}
This should do it...
Timer timer = new Timer();
public Form1()
{
InitializeComponent();
timer.Tick += Timer_Tick;
timer.Interval = 1000;
timer.Start();
}
int lastNotify = 0;
private void Timer_Tick(object sender, EventArgs e)
{
if ((DateTime.Now.Hour == 16 && lastNotify != 16) || (DateTime.Now.Hour == 21 && lastNotify != 21))
{
this.notifyIcon1.BalloonTipText = "Whatever";
this.notifyIcon1.BalloonTipTitle = "Title";
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(3);
lastNotify = DateTime.Now.Hour;
}
}