Why is "Dim instance As New Timer" not correct?

  • Thread starter Anil Gupte/iCinema.com
  • Start date
A

Anil Gupte/iCinema.com

When I use this

Dim instance As New Timer

I get the error: Error 1 Overload resolution failed because no accessible
'New' accepts this number of arguments.

Yet, in the help section for Timer (in VB 2005) this is exactly the syntax
shown. I also tried:

Dim instance As Timer = New Timer

and that gives the same error.
 
A

Armin Zingler

Anil Gupte/iCinema.com said:
When I use this

Dim instance As New Timer

I get the error: Error 1 Overload resolution failed because no
accessible 'New' accepts this number of arguments.

Yet, in the help section for Timer (in VB 2005) this is exactly the
syntax shown. I also tried:

Dim instance As Timer = New Timer

and that gives the same error.

Which kind of Timer? There is not only one.
- System.Windows.Forms.Timer
- System.Timers.Timer
- System.Threading.Timer

If you use the latter one, it does not have a parameterless concstructor,
which explains the error message. Import another namespace or use the full
qualified name to specify one of the other timers. If they are not
available, ouy ahve to set a reference to the containing assembly.


Armin
 
K

kimiraikkonen

When I use this

Dim instance As New Timer

I get the error: Error 1 Overload resolution failed because no accessible
'New' accepts this number of arguments.

Yet, in the help section for Timer (in VB 2005) this is exactly the syntax
shown. I also tried:

Dim instance As Timer = New Timer

and that gives the same error.

I think you're referring to System.Threading.Timer, hence you get the
error because Timer object under System.Threading doesn't accept empty
constructor, see constructor overload list here:
http://msdn.microsoft.com/en-us/library/system.threading.timer.timer(VS.80)..aspx

If you want to instantiate System.Timers.Timer, you can use it with
empty constructor to initialize Timer object:

Dim instance As New System.Timers.Timer
http://msdn.microsoft.com/en-us/library/system.timers.timer.timer.aspx

Hope this helps,

Onur Güzel
 
A

Anil Gupte/iCinema.com

Thanx. This brings up a question I was going to ask next anyway. What is
the best way to set up a Timer that does not hog the entire CPU? I assume
that is the System.Threading.Timer with a priority set to Normal or
something like that? I was going to instantiate a Timer and then cacll it
from a Thread. But I guess System.Threading.Timer will be better. Are
there some good examples of usage in terms of controlling some processes (I
want to be able to monitor a process from my Timer and then pause it and
restart it as needed).

Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com
www.wizo.tv
When I use this

Dim instance As New Timer

I get the error: Error 1 Overload resolution failed because no accessible
'New' accepts this number of arguments.

Yet, in the help section for Timer (in VB 2005) this is exactly the syntax
shown. I also tried:

Dim instance As Timer = New Timer

and that gives the same error.

I think you're referring to System.Threading.Timer, hence you get the
error because Timer object under System.Threading doesn't accept empty
constructor, see constructor overload list here:
http://msdn.microsoft.com/en-us/library/system.threading.timer.timer(VS.80).aspx

If you want to instantiate System.Timers.Timer, you can use it with
empty constructor to initialize Timer object:

Dim instance As New System.Timers.Timer
http://msdn.microsoft.com/en-us/library/system.timers.timer.timer.aspx

Hope this helps,

Onur Güzel
 
C

Cor Ligthert[MVP]

Anil,

As long as it is not for a service or to be used in an extra thread use the

System.Forms.Timer, that is simple the best but does not work in the above
situations

Cor
 
J

jp2msft

Anil,

Name your variable something besides "instance." Try TicToc or Timer1.

FYI: You can't name your variable int, string, class, or return either.
Understand?
 
A

Anil Gupte/iCinema.com

Umm, I have been programming for longer than you have been using your brain.
Of course I used different variable names. And BTW, I don't think instance
is incorrect to use as a variable name. The following are all valid.
Dim instance As Integer

Dim instance As String

Dim instance As Timer

Dim instance As System.Timers.Timer
 
C

Cor Ligthert[MVP]

Anil,

But it seems that you don't read the answers you get. Are you sure you are
creating a Service or somthing like that.

As I wrote earlier in this thread, the System.Timers.Timer is only for
Services or thinks like that.

Normally there is a better one for this. (There are 3 timers available)

Cor
 
A

Anil Gupte/iCinema.com

I have been reading my messages and am working on implementing
System.Threading.Timer but haven't got around to it. I was just dumping on
someone who was being rude and obnoxious.

Thanx,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top