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

后端 未结 2 1681
北荒
北荒 2021-02-15 05:12

i have error shown:

\'Timer\' is an ambiguous reference between \'System.Windows.Forms.Timer\' and \'System.Threading.Timer\' 
when i added the code for clock

2条回答
  •  心在旅途
    2021-02-15 05:32

    The problem is that you are

    using System.Windows.Forms;
    using System.Threading;
    

    Both of these namespaces have a Timer class and the compiler can't tell which one to use. When you declare your Timer, use the full name, either:

    System.Windows.Forms.Timer
    

    or

    System.Threading.Timer
    

    WinForms Timer Class

    Threading Timer Class

    Based on your usage of the class, I think you want System.Windows.Forms.Timer, like so:

        public SocketClient() 
        { 
            InitializeComponent(); 
            var timer = new System.Windows.Forms.Timer(); 
            timer.Tick += new EventHandler(TimerOnTick); 
            timer.Interval = 1000; 
            timer.Start(); 
        } 
    

提交回复
热议问题