473,508 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Single timer_tick() for multiple timers, how to get the sender

11 New Member
How do I know which Timer_Tick which timer object has raised the tick event?
Please refer some code.
Oct 6 '08 #1
13 1538
Plater
7,872 Recognized Expert Expert
You plan to use the same _tick() function for multiple timers?
What is the point of that?

At any rate, the "object sender" parameter that gets passed in, will tell you which object triggered the event.
Oct 6 '08 #2
nunu21
11 New Member
You plan to use the same _tick() function for multiple timers?
What is the point of that?

At any rate, the "object sender" parameter that gets passed in, will tell you which object triggered the event.

yes i plan to use the same_tick() function.
can u please send me some code to fetch that object and index of timer array using "object sender" parameter.
Oct 7 '08 #3
nunu21
11 New Member
yes i plan to use the same_tick() function.
can u please send me some code to fetch that object and index of timer array using "object sender" parameter.
Oct 7 '08 #4
Curtis Rutland
3,256 Recognized Expert Specialist
Once again, it doesn't make sense to use the same handler, but the "sender" parameter is a reference to the object that fired the event.

So you'd have to do something like
Expand|Select|Wrap|Line Numbers
  1. if(sender == timer1)
  2.   something;
  3. else if(sender == timer2)
  4.   somethingelse;
Or in your case you can loop through the array, comparing each iteration to sender.
Oct 7 '08 #5
nunu21
11 New Member
actually i am creating a array of System.Timers.timer. So it is nothing basically a one timer.
like timer[0];
timer[1] like this.

So i want to know which timer array has raised the tick event.
Oct 7 '08 #6
Curtis Rutland
3,256 Recognized Expert Specialist
Like I said:
Or in your case you can loop through the array, comparing each iteration to sender.
Oct 7 '08 #7
nunu21
11 New Member
i have created a timer array like this:
Expand|Select|Wrap|Line Numbers
  1. for (int i = 0; i < totalNumberOfThreads; i++)
  2.                 {
  3.                 tmrThread[totalNumberOfThreads] = new System.Timers.Timer();
  4.  
  5.                 tmrThread[totalNumberOfThreads].Enabled = true;
  6.                 tmrThread[totalNumberOfThreads].Interval = 120000;
  7.                 tmrThread[totalNumberOfThreads].Elapsed +=new System.Timers.ElapsedEventHandler(timer1_Tick);
  8. }
  9.  
  10. private void timer1_Tick(object sender, System.Timers.ElapsedEventArgs e)
  11.         {
  12.  
  13.             if (workerThreads[iIndex].IsAlive)
  14.             {
  15.                 workerThreads[iIndex].Abort();
  16.                 workerThreads[iIndex].Start();
  17.             }
  18.  
  19.         }
  20.  
in this case hoq could i know which timer object has raised the tick event. and then i want the index of that timer array.using that index i will start the thread.

Please help me out.
Oct 14 '08 #8
Plater
7,872 Recognized Expert Expert
Use the sender object like we said:
Expand|Select|Wrap|Line Numbers
  1. for (int i = 0; i < tmrThread.Length; i++)
  2. {
  3.    if (sender==tmrThread[i])
  4.    {//this is the one that sent the request
  5.    }
  6. }
  7.  
Oct 14 '08 #9
nunu21
11 New Member
i am doing this

Expand|Select|Wrap|Line Numbers
  1. for (int i = 0; i < tmrThread.Length; i++)
  2.             {
  3.                 if (sender == tmrThread[i])
  4.                 {
  5.                     workerThreads[i].Abort();
  6.                     workerThreads[i].Start();
  7.                 }
  8.             }
but it's not working.
Oct 14 '08 #10
Curtis Rutland
3,256 Recognized Expert Specialist
Please use [code] tags when you post code. It makes it far easier for us to read, and the easier it is for us, the more likely you are to get good help.

MODERATOR
Oct 14 '08 #11
nunu21
11 New Member
soryy but it's not working.
Oct 14 '08 #12
nunu21
11 New Member
In sender value is 'System.Timers.Timer' and in tmrThread[i] the value is different.

How it is going to check?
Oct 14 '08 #13
Plater
7,872 Recognized Expert Expert
tmrThread[i] is an isntance of System.Timers.Timer, the sender object is a System.Timer.Timer, this should not be a difficult concept?
Or did I miss something?

Its not any different then assigning a single buttonclick eventhandler to multiple buttons.
Oct 14 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1744
by: Dmitry Demchuk | last post by:
Hi everybody. Recently I ran into situation with System.Threading.Timer in my ASP.NET application. I reinstalled Windows on one of my servers and got timers stop firing events after while, they...
0
1736
by: Cider123 | last post by:
I was originally using: System.Windows.Forms.Timer It started to lock my Window Service up, so I went to the next evolution: System.Threading.Timer All was good. I was using it to send...
3
2180
by: Nathan Kovac | last post by:
I have a feeling I am missing something simple, but I just can't find it. Perhaps someone can give me a lead on where to look. I will describe the issue then post my code to the web service. My...
10
2668
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...
6
14990
by: Gene Hubert | last post by:
I seem to be getting crazy results when I have multiple System.Windows.Forms.Timer objects in the same form running at the same time. When only one timer is running I get the expected behavior. ...
5
9854
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...
8
3160
by: Jerry Spence1 | last post by:
I am trying to create timers on demand by doing the following: Dim NewTimer As New System.Timers.Timer NewTimer.Interval = 10000 AddHandler NewTimer.Elapsed, AddressOf Timeup NewTimer.Enabled =...
4
11087
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
8606
by: Steve Lowe | last post by:
Hi, I'm getting into VB.net with the help of a few books, but have got a problem grasping how to implement a system.timers.timer Only 1 of my 3 books mentions timers and that's a...
0
7226
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
7125
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...
0
7328
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
7388
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
7499
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...
1
5055
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...
0
3199
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
1561
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 ...
1
767
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.