473,799 Members | 3,390 Online
Bytes | Software Development & Data Engineering Community
+ 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(Ti mer_Tick);
timer.Interval = 1000 * obj.Interleaved Message.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 7766
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(Ti mer_Tick);
timer.Interval = 1000 * obj.Interleaved Message.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(Ti mer_Tick);
timer[i].Interval = 1000 * obj[i].InterleavedMes sage.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(Ti mer_Tick);
timer[i].Interval = 1000 * obj[i].InterleavedMes sage.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
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 {
9
7879
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 might need to carry out some back-end processing without pausing the individual users' Session while that process runs. E.g. I might provide the ability for a user to upload a text file of job
10
2710
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 two forms (frmSplash and frmMain) and a code Module setup as my startup object. Here is the code that I have, when I try to run this part of the splash screen form shows and then program terminates. What am I doing wrong? Thanks,
5
9889
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 regularly; like every 1.5 secs. or so. I only ran into one issue - the MyTimer_Elapsed event handler was not updating the screen correctly all the time, often leaving large chunks of the screen un-painted for several seconds. On a whim I decided to...
3
3696
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 site, performs a search based on POST variables, retrieves the code, parses the information (including a url for a thumbnail image) and displays the results. I am using threads, since the program will appear to freeze while
1
2117
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: static System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); private void dg_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { System.Timers.Timer timer = new System.Timers.Timer();
4
11133
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...
3
3942
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 for the nonstatic field, method, or property 'TestTimerIntervalFromConfig.Class1.timer1_Elapsed(object, System.Timers.ElapsedEventArgs)' using System;
5
12250
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
9687
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
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
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
10257
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
10029
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...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.