cant pass parameter to method?

I'm using a timer but can't pass a parameter in ProcessDir.
The error is method name expected.
timer.Elapsed += new ElapsedEventHandler(ProcessDir("C:\\test\\"));
timer.Interval = 5000;
timer.Enabled = true;
[246 byte] By [JACKWEBS] at [2007-11-20 11:07:01]
# 1 Re: cant pass parameter to method?
Anytime you add an event handler, you need to add it according to the event delegate's signature. See ElapsedEventDelegate (http://msdn2.microsoft.com/en-us/library/system.timers.elapsedeventhandler(VS.71).aspx) in msdn for a code snippet.

Here's a snippet from the docs (notice how the OnTimeEvent method is declared and called?).

public class Timer1
{

public static void Main()
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 5 seconds.
aTimer.Interval=5000;
aTimer.Enabled=true;

Console.WriteLine("Press \'q\' to quit the sample.");
while(Console.Read()!='q');
}

// Specify what you want to happen when the Elapsed event is raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine("Hello World!");
}
}
Arjay at 2007-11-9 11:36:15 >
# 2 Re: cant pass parameter to method?
If you read MSDN you'll notice that you are confusing the meaning of the first parameter. It does not mean that you can pass an object as you are trying to do. It is a reference to the timer object that threw the event.

Open up your copy of Visual Studio then under Help | Search, enter "System.Timers.Timer.ElapsedEventHandler" and click search. You will find the following:


public delegate void ElapsedEventHandler (
Object sender,
ElapsedEventArgs e
)


If you would provide more information as to what you are trying to do. Someone may be able to help you find another solution.
Kensino at 2007-11-9 11:37:16 >