0

I am trying to set up a timer in c#. In "using" part I have included this

using System.Windows.Forms.Timer;

My timer looks like this:

private Timer timer1;
public void InitTimer()
{
     timer1 = new Timer();
     timer1.Tick += new EventHandler(timer1_Tick);
     timer1.Interval = 1000; 
     timer1.Start();
}

However "Timer" is underlined, and I am getting this error:

"The type namespace 'Timer' could not be found(are you missing a using directive or an assembly reference?)"

I thought, that this will be included by default. If not, what do I need to include as a reference?

Thank you.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user2886091
  • 725
  • 7
  • 16
  • 29

2 Answers2

2

The namespace should be:

using System.Windows.Forms;

Timer is a class within that namespace.

Eren Ersönmez
  • 38,383
  • 7
  • 71
  • 92
0

You need to add reference to the System.Windows.Forms DLL, if it is not a Windows Form Application. And if it is, please post a full snippet if possible.

Another option is to use the System.Threading.Timers namespace.

Raja Nadar
  • 9,409
  • 2
  • 32
  • 41