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

后端 未结 2 1682
北荒
北荒 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:34

    There are various options here:

    • Use an alias:

      using UITimer = System.Windows.Forms.Timer;
      
      ...
      UITimer timer = new UITimer();
      
    • Use the fully qualified name:

      System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
      
    • Use a namespace alias:

      using WinForms = System.Windows.Forms;
      ...
      WinForms::Timer timer = new WinForms::Timer();
      

    However, I would personally suggest splitting up the user interface code from the network code - at which point it's unlikely to be an issue.

    I would also note that you're currently reading from the stream without taking the return value into account - that's a bad idea, as you don't know how much of the buffer actually contains new data.

提交回复
热议问题