This is my Code:
private void btnReminder_Click(object sender, EventArgs e)
{
timer2.Start();
}
private void timer2_Tick(object sender, EventArgs e)
{
DateTime Date = DateTimePickerReminderDate.Value;
DateTime Time = DateTimePickerReminderTime.Value;
if (DateTime.Now.CompareTo(Date) > 0 && DateTime.Now.CompareTo(Time) > 0)
{
Date = DateTime.MaxValue;
Time = DateTime.MaxValue;
MessageBox.Show("Your Reminder");
timer2.Stop();
}
}
When I set the reminder it working as expected and Showing the message at right sated time.But the problem is,it continuously giving pop up of messagebox I tried to clear this bug but I am unsuccessful in it.So right now I need the experts advice so please help me for clear this bug.
The MessageBox
will block your UI thread while displayed and you will not reach the timer.Stop()
before you click the dialog away.
Try stopping the timer before you display your MessageBox
:
private void timer2_Tick(object sender, EventArgs e)
{
DateTime Date = DateTimePickerReminderDate.Value;
DateTime Time = DateTimePickerReminderTime.Value;
if (DateTime.Now.CompareTo(Date) > 0 && DateTime.Now.CompareTo(Time) > 0)
{
timer2.Stop();
Date = DateTime.MaxValue;
Time = DateTime.MaxValue;
MessageBox.Show("Your Reminder");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With