4

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.

1 Answer 1

12

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"); } } 
Sign up to request clarification or add additional context in comments.

4 Comments

@Rock if an answer solved your problem you should accept it so that other people will know the problem is solved.
@Zohar Peled Yes I am accepting by saying Thank You in my previous comment. Is their any other way to do this please tell me I will definitely do that:)
@Rock: There is a V mark under the answer score that you should click. that will mark the answer as accepted, so that when people look at the question list, the number of answers is colored in yellow instead of white. This also gives 15 reputation points to the user that answered the question as well as 2 reputation points to the user that asked the question.
@Zohar Pared I keep in mind your suggestion and I am definitely follow it from now on ward:)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.