Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
C#
private void CountdownTimer_Load(object sender, EventArgs e)
        {
            Timer MyTimer = new Timer();
            MyTimer.Interval = (20 * 60 * 1000); // 20 mins
            MyTimer.Tick += new EventHandler(MyTimer_Tick);
            MyTimer.Start();
        }

        private void MyTimer_Tick(object sender, EventArgs e)
        {
            MessageBox.Show("time is up");
            this.Close();
        }


Timer MyTimer = new Timer();

ERROR:
Timer' is a 'namespace' but is used like a 'type'


how to solve this problem and one more doubt how to give Stopwatch value (minutes,seconds calculation for above timer) to a label
Posted
Updated 5-Dec-12 2:17am
v2
Comments
Deenuji 5-Dec-12 8:45am    
Did u use timers Namespace in this project?

If you run into this issue with a class that shares the same name as a namespace, then you need to fully qualify the class when you use it.
C#
System.Timers.Timer MyTimer...
 
Share this answer
 
 
Share this answer
 
For resolving error:
You might have given some class name or namespace as 'Timer'. Verify the same and rename accordingly. I noticed one thing: You have to set Enabled property True before Timer.Start()

For showing time on a label:
Store DateTime.Now() to a class level variable just before starting the timer. In the MyTimer_Tick event, subtract this variable from current time. Then you will get a TimeSpan which contains elapsed hours,minutes and seconds.
 
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