By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

User Timer in Class

P: n/a
Hi all,

I just want to know how to use a System.Windows.Forms.Timer in class. I
know how to use it on a form, but I don't know how to "put" a timer in a
class (DLL)

Thx !!!
Nov 20 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
"Mathieu" <ma*************@videotron.ca> schrieb

I just want to know how to use a System.Windows.Forms.Timer in
class. I know how to use it on a form, but I don't know how to "put"
a timer in a class (DLL)


There is no mystery behind. :-) The Form designer just generates one line
for you:

Private WithEvents MyTimer As New System.Windows.Forms.Timer

In other classes you can write this line on your own.

You might consider make your class a component, so the component designer
will be available and you can drop a Timer on the designer. Details:
http://msdn.microsoft.com/library/en...tAuthoring.asp
http://msdn.microsoft.com/library/en...essentials.asp

Apart from this, why do you need such a timer in a class? The timer should
only be used in a UI (user interface) context.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #2

P: n/a
"Mathieu" <ma*************@videotron.ca> schrieb

I just want to know how to use a System.Windows.Forms.Timer in
class. I know how to use it on a form, but I don't know how to "put"
a timer in a class (DLL)


There is no mystery behind. :-) The Form designer just generates one line
for you:

Private WithEvents MyTimer As New System.Windows.Forms.Timer

In other classes you can write this line on your own.

You might consider make your class a component, so the component designer
will be available and you can drop a Timer on the designer. Details:
http://msdn.microsoft.com/library/en...tAuthoring.asp
http://msdn.microsoft.com/library/en...essentials.asp

Apart from this, why do you need such a timer in a class? The timer should
only be used in a UI (user interface) context.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #3

P: n/a
Mathieu,

You can use this code in your class:

---------------------------
Private Withevents mTimer as New System.Windows.Forms.Timer

Private Sub TimerTickedHandler(sender as object, e as EventArgs) handles
mTimer.Tick
' Handle the timer tick
End Sub
---------------------------

You'll need to add code to your class to enable/disable the timer.

I suggest you have a look at the other timers (System.Timers.Timer and
System.Threading.Timer) as they provide a little bit more functionality than
the Windows Forms timer, but need a little bit of care when using with
windows forms as their events can be raised on different threads.

Hope this helps,

Trev.
"Mathieu" <ma*************@videotron.ca> wrote in message
news:ej**************@TK2MSFTNGP10.phx.gbl...
Hi all,

I just want to know how to use a System.Windows.Forms.Timer in class. I
know how to use it on a form, but I don't know how to "put" a timer in a
class (DLL)

Thx !!!

Nov 20 '05 #4

P: n/a
Mathieu,

You can use this code in your class:

---------------------------
Private Withevents mTimer as New System.Windows.Forms.Timer

Private Sub TimerTickedHandler(sender as object, e as EventArgs) handles
mTimer.Tick
' Handle the timer tick
End Sub
---------------------------

You'll need to add code to your class to enable/disable the timer.

I suggest you have a look at the other timers (System.Timers.Timer and
System.Threading.Timer) as they provide a little bit more functionality than
the Windows Forms timer, but need a little bit of care when using with
windows forms as their events can be raised on different threads.

Hope this helps,

Trev.
"Mathieu" <ma*************@videotron.ca> wrote in message
news:ej**************@TK2MSFTNGP10.phx.gbl...
Hi all,

I just want to know how to use a System.Windows.Forms.Timer in class. I
know how to use it on a form, but I don't know how to "put" a timer in a
class (DLL)

Thx !!!

Nov 20 '05 #5

P: n/a
Mathieu,
In addition to Armin's suggestion of how to do it.

Remember that to use System.Windows.Forms.Timer your application will need
the "message loop" running, which means it needs to have at least one form
running or you called System.Windows.Forms.Application.Run in your Sub Main.

If you are not otherwise using Windows Forms in your application you may
want to consider either the System.Threading.Timer class or the
System.Timers.Timer class.

Being a DLL it is hard to ensure that the main application will call
Application.Run!

Hope this helps
Jay

"Mathieu" <ma*************@videotron.ca> wrote in message
news:ej**************@TK2MSFTNGP10.phx.gbl...
Hi all,

I just want to know how to use a System.Windows.Forms.Timer in class. I
know how to use it on a form, but I don't know how to "put" a timer in a
class (DLL)

Thx !!!

Nov 20 '05 #6

P: n/a
Mathieu,
In addition to Armin's suggestion of how to do it.

Remember that to use System.Windows.Forms.Timer your application will need
the "message loop" running, which means it needs to have at least one form
running or you called System.Windows.Forms.Application.Run in your Sub Main.

If you are not otherwise using Windows Forms in your application you may
want to consider either the System.Threading.Timer class or the
System.Timers.Timer class.

Being a DLL it is hard to ensure that the main application will call
Application.Run!

Hope this helps
Jay

"Mathieu" <ma*************@videotron.ca> wrote in message
news:ej**************@TK2MSFTNGP10.phx.gbl...
Hi all,

I just want to know how to use a System.Windows.Forms.Timer in class. I
know how to use it on a form, but I don't know how to "put" a timer in a
class (DLL)

Thx !!!

Nov 20 '05 #7

P: n/a
Thx All
I will use System.Timers.Timer !!!
"Codemonkey" <hu*********@hotmail.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
Mathieu,

You can use this code in your class:

---------------------------
Private Withevents mTimer as New System.Windows.Forms.Timer

Private Sub TimerTickedHandler(sender as object, e as EventArgs) handles
mTimer.Tick
' Handle the timer tick
End Sub
---------------------------

You'll need to add code to your class to enable/disable the timer.

I suggest you have a look at the other timers (System.Timers.Timer and
System.Threading.Timer) as they provide a little bit more functionality than the Windows Forms timer, but need a little bit of care when using with
windows forms as their events can be raised on different threads.

Hope this helps,

Trev.
"Mathieu" <ma*************@videotron.ca> wrote in message
news:ej**************@TK2MSFTNGP10.phx.gbl...
Hi all,

I just want to know how to use a System.Windows.Forms.Timer in class. I
know how to use it on a form, but I don't know how to "put" a timer in a
class (DLL)

Thx !!!


Nov 20 '05 #8

P: n/a
Thx All
I will use System.Timers.Timer !!!
"Codemonkey" <hu*********@hotmail.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
Mathieu,

You can use this code in your class:

---------------------------
Private Withevents mTimer as New System.Windows.Forms.Timer

Private Sub TimerTickedHandler(sender as object, e as EventArgs) handles
mTimer.Tick
' Handle the timer tick
End Sub
---------------------------

You'll need to add code to your class to enable/disable the timer.

I suggest you have a look at the other timers (System.Timers.Timer and
System.Threading.Timer) as they provide a little bit more functionality than the Windows Forms timer, but need a little bit of care when using with
windows forms as their events can be raised on different threads.

Hope this helps,

Trev.
"Mathieu" <ma*************@videotron.ca> wrote in message
news:ej**************@TK2MSFTNGP10.phx.gbl...
Hi all,

I just want to know how to use a System.Windows.Forms.Timer in class. I
know how to use it on a form, but I don't know how to "put" a timer in a
class (DLL)

Thx !!!


Nov 20 '05 #9

P: n/a
Cor
Hi Mathieu

In addition to all others

Try a time this, make a new program with only a timer from the toolbox on
it,
set the properties and open your code.

Look now at the code in Windows designer code (you can open that by pushing
the +)

That is the same as you can make and use on every form.

Than delete it and drag from the component box a timer (that is the
system.timers.timer) and try the same. That one you can use as far as I know
in any class.

But I have the same question as Armin, why would you make from this your own
DLL.
Or do you want to make your own Seiko's

I hope this helps,

Cor
Nov 20 '05 #10

P: n/a
Cor
Hi Mathieu

In addition to all others

Try a time this, make a new program with only a timer from the toolbox on
it,
set the properties and open your code.

Look now at the code in Windows designer code (you can open that by pushing
the +)

That is the same as you can make and use on every form.

Than delete it and drag from the component box a timer (that is the
system.timers.timer) and try the same. That one you can use as far as I know
in any class.

But I have the same question as Armin, why would you make from this your own
DLL.
Or do you want to make your own Seiko's

I hope this helps,

Cor
Nov 20 '05 #11

P: n/a
I need a Timer in my class because I need a "Timeout Connection".
Thx !!!
"Cor" <no*@non.com> wrote in message
news:uq**************@TK2MSFTNGP11.phx.gbl...
Hi Mathieu

In addition to all others

Try a time this, make a new program with only a timer from the toolbox on
it,
set the properties and open your code.

Look now at the code in Windows designer code (you can open that by pushing the +)

That is the same as you can make and use on every form.

Than delete it and drag from the component box a timer (that is the
system.timers.timer) and try the same. That one you can use as far as I know in any class.

But I have the same question as Armin, why would you make from this your own DLL.
Or do you want to make your own Seiko's

I hope this helps,

Cor

Nov 20 '05 #12

P: n/a
I need a Timer in my class because I need a "Timeout Connection".
Thx !!!
"Cor" <no*@non.com> wrote in message
news:uq**************@TK2MSFTNGP11.phx.gbl...
Hi Mathieu

In addition to all others

Try a time this, make a new program with only a timer from the toolbox on
it,
set the properties and open your code.

Look now at the code in Windows designer code (you can open that by pushing the +)

That is the same as you can make and use on every form.

Than delete it and drag from the component box a timer (that is the
system.timers.timer) and try the same. That one you can use as far as I know in any class.

But I have the same question as Armin, why would you make from this your own DLL.
Or do you want to make your own Seiko's

I hope this helps,

Cor

Nov 20 '05 #13

P: n/a
Just be careful if you are using the System.Timers.Timer timer when you are
dealing with Windows forms. Always be sure to call the Invoke() method of
the form if you want to call any other method on the form.

Trev

"Mathieu" <ma*************@videotron.ca> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thx All
I will use System.Timers.Timer !!!
"Codemonkey" <hu*********@hotmail.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
Mathieu,

You can use this code in your class:

---------------------------
Private Withevents mTimer as New System.Windows.Forms.Timer

Private Sub TimerTickedHandler(sender as object, e as EventArgs) handles
mTimer.Tick
' Handle the timer tick
End Sub
---------------------------

You'll need to add code to your class to enable/disable the timer.

I suggest you have a look at the other timers (System.Timers.Timer and
System.Threading.Timer) as they provide a little bit more functionality

than
the Windows Forms timer, but need a little bit of care when using with
windows forms as their events can be raised on different threads.

Hope this helps,

Trev.
"Mathieu" <ma*************@videotron.ca> wrote in message
news:ej**************@TK2MSFTNGP10.phx.gbl...
Hi all,

I just want to know how to use a System.Windows.Forms.Timer in class. I know how to use it on a form, but I don't know how to "put" a timer in a class (DLL)

Thx !!!



Nov 20 '05 #14

P: n/a
I've used CCRP Timer and think it's brilliant for VB6 applications. Although
it can be used in DotNet via COM interop, there really isn't any need to use
it because of the System.Timers.Timer and System.Threading.Timer classes
which are better suited to the multithreaded-capable dotnet world.

Just my humble opinion.

Trev.

"avillela" <av******@cpqd.com.br> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
there's a timer that can be used into a class. it's a High Performance Timer Object called CCRP.

you hate to make a reference to the object.

then

declare:
Private WithEvents TimerTX As ccrpTimer

instance:
Set TimerTX = New ccrpTimer

define the interval:
TimerTX.Interval = 500 (mls)

to activate the timer:
TimerTX.Enabled = True

after make a reference
Private Sub TimerTX_Timer(ByVal Milliseconds As Long)
your code
End Sub

that's all

André-Brazil



"Mathieu" <ma*************@videotron.ca> escreveu na mensagem
news:uO**************@TK2MSFTNGP09.phx.gbl...
I need a Timer in my class because I need a "Timeout Connection".
Thx !!!
"Cor" <no*@non.com> wrote in message
news:uq**************@TK2MSFTNGP11.phx.gbl...
Hi Mathieu

In addition to all others

Try a time this, make a new program with only a timer from the toolbox on it,
set the properties and open your code.

Look now at the code in Windows designer code (you can open that by

pushing
the +)

That is the same as you can make and use on every form.

Than delete it and drag from the component box a timer (that is the
system.timers.timer) and try the same. That one you can use as far as
I know
in any class.

But I have the same question as Armin, why would you make from this
your own
DLL.
Or do you want to make your own Seiko's

I hope this helps,

Cor



Nov 20 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.