Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
2.00/5 (4 votes)
See more: , +
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:-
C#
Timer1.Start(); // Timer in initialized.

C#
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
Updated 17-Aug-12 9:06am
v2
Comments
Sergey Alexandrovich Kryukov 17-Aug-12 15:08pm    
Where is Interval and other related to timer code?
--SA
[no name] 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?
--SA
[no name] 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

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900