Windows Develop Bookmark and Share   
 index > Windows Forms General > using System.Threading; + Error
 

using System.Threading; + Error

hello i have a simple stopwatch which also works. but is add using System.Threading; it gave an error, i need Threading for my backgroundworkers

'Timer' is an ambiguous reference between 'System.Threading.Timer' and 'System.Windows.Forms.Timer'


       Timer timer;       

        public MainForm()
        {
            InitializeComponent();
            timer = new Timer();
            timer.Tick += new EventHandler(timer_Tick);
 
        }

        void timer_Tick(object sender, EventArgs e)
        {
            ms++;
            this.Refresh();
            string strms = "";
            string strss = "";
            string strmm = "";
            string strhh = "";
            strms = GetStringValue(ms);
            strss = GetStringValue(ss);
            strmm = GetStringValue(mm);
            strhh = GetStringValue(hh);
            if (ms == 9)
            {               
                ms = 0;
                ss++;
                strss = GetStringValue(ss);
                if (ss == 59)
                {                   
                    ss = 0;
                    mm++;
                    strmm = GetStringValue(mm);
                    if (mm == 59)
                    {
                        mm = 0;
                        hh++;
                        strhh = GetStringValue(hh);
                        if (hh == 12)
                        {
                            hh = 0;
                        }
                    }
                }
            }

            strTime = strhh + ":" + strmm + ":" + strss;
            lblTime.Text = strTime;
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            if (btnStart.Text == "&Start")
            {
                btnStart.Text = "&Stop";
                timer.Start();
            }
            else
            {
                btnStart.Text ="&Start";
                timer.Stop();
                ms = 0;
                ss = 0;
                mm = 0;
                hh = 0;
            }
        }

        private string GetStringValue(int nValue)
        {
            string strValue = "00";
            if (nValue == 0)
            {
                return strValue;
            }
            if (nValue < 10)
            {
                strValue = "0" + nValue.ToString();
                return strValue;
            }
            return nValue.ToString();
        }




Power-Mosfet  Wednesday, September 16, 2009 8:13 PM
you have to specify which Time class you are using because Timer class is present in both System.Threading and System.Windows.Form namespaces. and .NET doesnot know which one you are refering to.

use either
timer = new System.Threading.Timer();
or
timer = new System.Windows.Form.Timer();
Paras
  • Marked As Answer bynobugzMVP, ModeratorWednesday, September 16, 2009 11:55 PM
  • Proposed As Answer byRudedog2 Wednesday, September 16, 2009 11:24 PM
  •  
paras kumar  Wednesday, September 16, 2009 9:08 PM
you have to specify which Time class you are using because Timer class is present in both System.Threading and System.Windows.Form namespaces. and .NET doesnot know which one you are refering to.

use either
timer = new System.Threading.Timer();
or
timer = new System.Windows.Form.Timer();
Paras
  • Marked As Answer bynobugzMVP, ModeratorWednesday, September 16, 2009 11:55 PM
  • Proposed As Answer byRudedog2 Wednesday, September 16, 2009 11:24 PM
  •  
paras kumar  Wednesday, September 16, 2009 9:08 PM
Use the Windows Forms timer.
Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2  Wednesday, September 16, 2009 11:24 PM

You can use google to search for other answers

Custom Search

More Threads

• ToolBox icon doesn't appear in the toolbox
• Possible to set the browsable attribute on a property at runtime?
• In a numericUpDown, can I separate decimals with a point instead of a comma
• How to make the form to repaint?
• Urgent help on Data Grid issue needed
• Backgroundworker signaling
• How do you turn 'redraw' off/on?
• C# please help
• Motherboard resource accessing
• Securing files