473,473 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

creating an array of System.Windows.Forms.Timers

Hi,

I have a number of objects for which I want to create a timer for.
So for each object I would like to have a timer which runs at a
different interval.

For a single timer I know how to implement

timer = new System.Windows.Forms.Timer();
timer.Tick += new EventHandler(Timer_Tick);
timer.Interval = 1000 * obj.InterleavedMessage.Time;
timer.Enabled = true;

But how can I have an array of timers for an array of objects which
will have different intervals?
For each timer I would like to call a different timer_tick handler.

Cheers

Feb 1 '06 #1
4 7749
TheJediMessiah wrote:
I have a number of objects for which I want to create a timer for.
So for each object I would like to have a timer which runs at a
different interval.

For a single timer I know how to implement

timer = new System.Windows.Forms.Timer();
timer.Tick += new EventHandler(Timer_Tick);
timer.Interval = 1000 * obj.InterleavedMessage.Time;
timer.Enabled = true;

But how can I have an array of timers for an array of objects which
will have different intervals?
For each timer I would like to call a different timer_tick handler.


Just do it the same way you would with any other array:

Timer[] timers = new Timer[someSize];

timers[0] = new Timer();
timers[0].Tick += ...;

etc

Jon

Feb 1 '06 #2
You have not filled in the most critical part but just left it with ...

If I create an array of timers like you have suggested.

Timer[] timers = new Timer[someSize];
for(int i=0;i<someSize;i++)
{
timer[i].Tick += new EventHandler(Timer_Tick);
timer[i].Interval = 1000 * obj[i].InterleavedMessage.Time;
timer[i].Enabled = true;
}

Is this correct?
How do I know which Timer_Tick which timer object has raised it???

Feb 2 '06 #3
TheJediMessiah wrote:
You have not filled in the most critical part but just left it with ...
Well yes - I was assuming that having filled in a couple of properties,
the way to do the rest was obvious.
If I create an array of timers like you have suggested.

Timer[] timers = new Timer[someSize];
for(int i=0;i<someSize;i++)
{
timer[i].Tick += new EventHandler(Timer_Tick);
timer[i].Interval = 1000 * obj[i].InterleavedMessage.Time;
timer[i].Enabled = true;
}

Is this correct?
Yes.
How do I know which Timer_Tick which timer object has raised it???


The first parameter to the event is the "source" which should be the
Timer generating the event.

Jon

Feb 2 '06 #4
Thanks.
I created subclass of the Timer class and added an ID property so I
knew which timer was passed into TImer_Tick.

Thanks again for your help.

Feb 2 '06 #5

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

Similar topics

4
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...
9
by: Mark Rae | last post by:
Hi, I've seen several articles about using System Timers in ASP.NET solutions, specifically setting them up in Global.asax' Application_OnStart event. I'm thinking about the scenario where I...
10
by: WhiteSocksGuy | last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have...
5
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated...
3
by: EnglishMan69 | last post by:
Hello All, I am using VB2005 Beta 2 in VS 2005 and am running into a small problem. I need to be able to add a picture box to the main form from within a thread. The program goes to a web...
1
by: melanieab | last post by:
Hi, I'm have a datagrid, and I'm trying to have a tooltip pop up if a cell has been hovered on for 2 seconds. I was thinking of using DataGrid.Hover, but then decided to try this instead: ...
4
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...
3
by: hazz | last post by:
Why do I get this error for this simple console app. It is complaining about the 'timer1_Elapsed' argument in System.Timers.ElapsedEventHandler(timer1_Elapsed); An object reference is required...
5
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
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.