Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

2 views
Skip to first unread message

Anil Gupte/iCinema.com

unread,
Oct 13, 2008, 6:34:49 AM10/13/08
to
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.

--
Anil Gupte
www.keeninc.net
www.icinema.com
www.wizo.tv


kimiraikkonen

unread,
Oct 13, 2008, 7:02:11 AM10/13/08
to
On Oct 13, 1:34 pm, "Anil Gupte/iCinema.com" <anil-l...@icinema.com>
wrote:

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

Armin Zingler

unread,
Oct 13, 2008, 6:54:21 AM10/13/08
to
"Anil Gupte/iCinema.com" <anil...@icinema.com> schrieb

> 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

Anil Gupte/iCinema.com

unread,
Oct 13, 2008, 2:40:02 PM10/13/08
to
Thanx, I will try that.

"Armin Zingler" <az.n...@freenet.de> wrote in message
news:%23WD6pLS...@TK2MSFTNGP06.phx.gbl...

Anil Gupte/iCinema.com

unread,
Oct 13, 2008, 2:42:54 PM10/13/08
to
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,

"kimiraikkonen" <kimirai...@gmail.com> wrote in message
news:a3ed2d79-32e7-43db...@s50g2000hsb.googlegroups.com...

Cor Ligthert[MVP]

unread,
Oct 14, 2008, 2:55:06 AM10/14/08
to
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

"Anil Gupte/iCinema.com" <anil...@icinema.com> schreef in bericht
news:u5keFOWL...@TK2MSFTNGP04.phx.gbl...

jp2msft

unread,
Oct 14, 2008, 10:34:11 AM10/14/08
to
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?

Anil Gupte/iCinema.com

unread,
Oct 15, 2008, 3:17:02 PM10/15/08
to
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

"jp2msft" <jp2...@discussions.microsoft.com> wrote in message
news:A42E0623-5A1C-4D33...@microsoft.com...

jp2msft

unread,
Oct 15, 2008, 5:05:01 PM10/15/08
to
Remind me to never offer any ideas or help to you again.

I do not develop in VB.

Anil Gupte/iCinema.com

unread,
Oct 16, 2008, 12:41:12 AM10/16/08
to
It is very obvious that you don't develop in VB!!!!

news:A62249B7-4F36-42CD...@microsoft.com...

Cor Ligthert[MVP]

unread,
Oct 16, 2008, 12:10:50 PM10/16/08
to
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

"Anil Gupte/iCinema.com" <anil...@icinema.com> wrote in message
news:OzAbgqvL...@TK2MSFTNGP06.phx.gbl...

Anil Gupte/iCinema.com

unread,
Oct 19, 2008, 2:40:51 PM10/19/08
to
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,

"Cor Ligthert[MVP]" <Notmyfi...@planet.nl> wrote in message
news:%239st$m6LJH...@TK2MSFTNGP05.phx.gbl...

0 new messages