473,761 Members | 5,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User Timer in Class

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
14 1501
"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
"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
Mathieu,

You can use this code in your class:

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

Private Sub TimerTickedHand ler(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.Threadin g.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******** ******@TK2MSFTN GP10.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
Mathieu,

You can use this code in your class:

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

Private Sub TimerTickedHand ler(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.Threadin g.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******** ******@TK2MSFTN GP10.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
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.Applicati on.Run in your Sub Main.

If you are not otherwise using Windows Forms in your application you may
want to consider either the System.Threadin g.Timer class or the
System.Timers.T imer 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******** ******@TK2MSFTN GP10.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
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.Applicati on.Run in your Sub Main.

If you are not otherwise using Windows Forms in your application you may
want to consider either the System.Threadin g.Timer class or the
System.Timers.T imer 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******** ******@TK2MSFTN GP10.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
Thx All
I will use System.Timers.T imer !!!
"Codemonkey " <hu*********@ho tmail.com> wrote in message
news:u5******** ******@TK2MSFTN GP12.phx.gbl...
Mathieu,

You can use this code in your class:

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

Private Sub TimerTickedHand ler(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.Threadin g.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******** ******@TK2MSFTN GP10.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
Thx All
I will use System.Timers.T imer !!!
"Codemonkey " <hu*********@ho tmail.com> wrote in message
news:u5******** ******@TK2MSFTN GP12.phx.gbl...
Mathieu,

You can use this code in your class:

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

Private Sub TimerTickedHand ler(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.Threadin g.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******** ******@TK2MSFTN GP10.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
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.t imer) 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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
464
by: Bilo | last post by:
I have a Windows Forms Class MainGUI I have declared MainGUI maingui; public System.ComponentModel.Container components = new Container(); in the Class I call another class MediaDriver with the Constructor class MediaDriver {
0
1924
by: Chris Millar | last post by:
I have a user control that i wish to extend to change the date when the user selects the numeric up down button. The code explains itself, hope someone can help. any ideas appreaciated.. Chris. code :
2
1427
by: Alfonso Morra | last post by:
Hi, I am writing a timer class that I want to be able to get to notify me (via a callback func), when a specified interval has elapsed. I have most of the timer functionality figured - however, I need to spawn a new thread to carry out the "time watch" - and I need to do this in a cross platform (Well Linux/Windows) way ... Any help will be much appreciated. The code (snippet) follows below:
2
4065
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: The MyService service on Local Computer started and then stopped. Some services stop automatically if they ahve no work to do, for example, the Perforamnce Logs and Alert service. I tried switching to a System.Threading.Timer and that didn't work...
4
11129
by: Liverpool fan | last post by:
I have a windows application written using VB .NET that encompasses a countdown timer modal dialog. The timer is a System.Timers.Timer with an interval of 1 second. AutoReset is not set so accepts the default of True. The Elapsed event handler updates the dialog box with how long before it will close, acting as a timer itself. The dialog has a time to close property which is checked every time the Elapsed event fires. The problem I have...
4
1695
by: Daniel | last post by:
Hey guys Here is what i want to do. I have made a multiplayer game that needs to when more than one player is ready start a countdown that the clients can see, so players can still join in this time frame and then after the time elapses the game starts. I am trying to do it lie this, my server controls all handling of the game logic, deciding who wins, who is next to play etc. For all the players to have their timers showing the same...
5
4916
by: muzilli | last post by:
Howdy all, I would like to know how can I insert a Timer object in my class library? This timer object will start and stop in a determinated part or event of my program. I know how to do this in Delphi or using a RAD tool and insert the Timer object in a form, but how to do in C# by hand and in a class library (without form), I don't know.
12
5534
by: Gina_Marano | last post by:
I have created an array of timers (1-n). At first I just created windows form timers but I read that system timers are better for background work. The timers will just be monitoring different directories and updating a database. No interaction with the GUI. Problem is that the system timers do not have a tag property so I can tie in an object. example (old way):
5
12247
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the event handlers may take longer than the interval for either of the timers, so it's possible for multiple events to fire "simultaneously" and for events to queue up. I'm attempting to get the timers to sync on some reference type object, or use...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.