Click here to Skip to main content
12,357,409 members (73,485 online)
Rate this:
 
Please Sign up or sign in to 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 5-Dec-12 2:16am
Edited 5-Dec-12 2:17am
v2
Comments
Deenu India 5-Dec-12 8:45am
   
Did u use timers Namespace in this project?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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.
System.Timers.Timer MyTimer...
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

Solution 4

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.
  Permalink  

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.160621.1 | Last Updated 5 Dec 2012
Copyright © CodeProject, 1999-2016
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