How can I call a MessageBox.Show command when the time is exactly 5pm in C#?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const double interval60Minutes = 1000; // milliseconds to one hour
System.Timers.Timer checkForTime = new System.Timers.Timer(interval60Minutes);
string Check = null;
private void Form1_Load(object sender, EventArgs e)
{
checkForTime.Elapsed += new ElapsedEventHandler(checkForTime_Elapsed);
checkForTime.Enabled = true;
}
public void checkForTime_Elapsed(object sender, ElapsedEventArgs e)
{
DateTime target = new DateTime(2016, 5, 8, 11, 58, 0);
DateTime now = DateTime.Now;
if (target.ToString("HH:mm:ss") == now.ToString("HH:mm:ss") && (Check == null))
{
MessageBox.Show("Welcome Admin");
checkForTime.Stop();
checkForTime.Enabled = false;
}
}
}
If I put just MessageBox.Show
without the if statement it works, but when I put a condition nothing happens. The timer won't stop I used both enabled = false and stop function.