Click here to Skip to main content
12,895,801 members (51,925 online)
Rate this:
Please Sign up or sign in to vote.
See more: .NET2.0 .NET3.5 C# .NET , +
I am working on Windows Application.
In a form I dragged one label and one timer control.
I have written the following code:-

On form load event:-
Timer1.Start(); // Timer in initialized.

private void timer1_Tick(object sender, EventArgs e)
            bool status = false;
            label1.Text = DateTime.Now.ToLongTimeString();
            DateTime time = Convert.ToDateTime("10:05:00 PM");
            if (DateTime.Now.ToLongTimeString() == time.ToLongTimeString())
                MessageBox.Show("Perfect Code.", "Timer Control", MessageBoxButtons.OK, MessageBoxIcon.Information);

I was running program at 10 pm so I entered 10 pm. Enter the timing after the current time.

Error in this program is that when the user time is equal to system time Message Box is shown 9 times. Help me sort out this.

Thanks in Advance....
Posted 17-Aug-12 9:04am
Updated 17-Aug-12 9:06am
Sergey Alexandrovich Kryukov 17-Aug-12 15:08pm
Where is Interval and other related to timer code?
Wes Aday 17-Aug-12 15:08pm
And how long is your timer interval?
Sergey Alexandrovich Kryukov 17-Aug-12 15:10pm
Bad code. Working with strings instead of time, calling a MessageBox from the time tick event handler. But first, what do you want to achieve?
learner'sbug 17-Aug-12 15:14pm
Its showing it 9 times because default interval is 100 milliseconds and your precision point is second but again what are you trying to do ?
Ank_ush 17-Aug-12 15:27pm
yes you r right
I changed it to 1000 and its done.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I set the time Interval of timer control to 1000, now it's showing only once.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 17 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100