How to declare timer?

  • Thread starter Thread starter Brett
  • Start date Start date
B

Brett

If I use the following code, the declaration is fine.
//no namespace
private System.Timers.Timer Clock;

This gives the error, "'Timer' is an ambiguous reference".
using System.Timers; //namespace doesn't make a difference
....
private Timer Clock;

What am I doing wrong?

Thanks,
Brett
 
Brett <[email protected]> said:
If I use the following code, the declaration is fine.
//no namespace
private System.Timers.Timer Clock;

This gives the error, "'Timer' is an ambiguous reference".
using System.Timers; //namespace doesn't make a difference
...
private Timer Clock;

What am I doing wrong?

There's more than one class called "Timer" in the framework.

System.Threading.Timer
System.Timers.Timer
System.Windows.Forms.Timer

Maybe more.

You already have one in scope, and adding the using directive brings in
another.
 
Steve Walker said:
There's more than one class called "Timer" in the framework.

System.Threading.Timer
System.Timers.Timer
System.Windows.Forms.Timer

Maybe more.

You already have one in scope, and adding the using directive brings in
another.

I see. I am doing this which brings in two timers:
using System.Windows.Forms;
using System.Threading;

I could narrow down the Clock declaration by providing a full path. Is
there another way?

Thanks,
Brett
 
Problem is that Timer exists in System.Windows.Forms namespace as well.
I think you have declared using System.Windows.Forms and using System.Timers
at once.
 
I see. I am doing this which brings in two timers:
using System.Windows.Forms;
using System.Threading;

I could narrow down the Clock declaration by providing a full path. Is
there another way?

You can alias namespaces like this:

using Stuff = System.Timers;
....
private Stuff.Timer Clock;
 
Steve Walker said:
You can alias namespaces like this:

using Stuff = System.Timers;
...
private Stuff.Timer Clock;

Ok, thanks.

Why if I do something like
this.IE_Inst.Stop();
C# will not automatically put the parentheses on Stop() so I get a compiler
error.

Brett
 
Back
Top