473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using System.Timers.ElapsedEventHandler to specify a method and and ElapsedEventArgs object

Using System.Timers.ElapsedEventHandler to specify a method and and
ElapsedEventArgs object

I've trawled the internet looking for some help on this topic. What I want
to do is, every x seconds call function y with some parameters. Simple.
The ElapsedEventArgs paramerter I want to pass in is an object "c" of a
custom type.
The following does not work:

Clock.Elapsed += new System.Timers.ElapsedEventHandler( OnTimer, new
ElapsedEventArgs( c ) );

"Method 'frmMain.OnTimer(object, System.Timers.ElapsedEventArgs)' referenced
without parentheses

I have put () after OnTimer but to no avail, can anyone point me to a
reliable sample which passes this second parameter in.

PT
Nov 16 '05 #1
1 13352
Max,

When you set the event handler to your code, you are setting the method
that will be called. You can't set the parameters that are passed to it.
That is reserved for the object firing the event. In this case. What you
want to do is make sure that your OnTimer method has access to the variable
"c" (store it on the class level, create a new instance, etc, etc). Then,
when your method is called, you pass "c" to whatever method you are going to
call in the event handler.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Max Adams" <ru************@hotmail.com> wrote in message
news:ue**************@TK2MSFTNGP12.phx.gbl...
Using System.Timers.ElapsedEventHandler to specify a method and and
ElapsedEventArgs object

I've trawled the internet looking for some help on this topic. What I
want
to do is, every x seconds call function y with some parameters. Simple.
The ElapsedEventArgs paramerter I want to pass in is an object "c" of a
custom type.
The following does not work:

Clock.Elapsed += new System.Timers.ElapsedEventHandler( OnTimer, new
ElapsedEventArgs( c ) );

"Method 'frmMain.OnTimer(object, System.Timers.ElapsedEventArgs)'
referenced
without parentheses

I have put () after OnTimer but to no avail, can anyone point me to a
reliable sample which passes this second parameter in.

PT

Nov 16 '05 #2

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

Similar topics

3
by: Peter Johnsson | last post by:
How come the eventhandler for the timer's elapsed time event is called over and over again, even though the AutoReset property is set to false, if you assign a new value to the timer objects...
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...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
3
by: ginguene | last post by:
Its supposed to be a very simple program, with a class to display the updated current time every second (CAnalogTime) inside a Label in my form, using ElapsedEventHandler from System.Timers; The...
2
by: Al | last post by:
I'm currently attempting to use PLink (the console component of PUTTY - see http://www.chiark.greenend.org.uk/~sgtatham/putty/) as a Telnet component as I may in future need to change to using SSH...
1
by: Jonathan Woods | last post by:
Hi there, I have three methods these need to execute at every interval time. I would like to know which option is better? Option A) Three System.Timers.Timer objects these execute each...
4
by: Ben | last post by:
Hello everybody I got confused by this problem for which I don't have a logical explanation. There is a Thread (ThreadA) which receives Events from another system thread (ThreadS). ThreadA then...
4
by: archana | last post by:
Hi all, I want to develop one windows service in which i want to provide some scheduling facility. What i want is to take start time frm one xml file and then at that specified start time. ...
3
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.