-
May 23rd, 2019, 01:56 PM
#1
Unable to pass Method as argument to ElapsedEventHandler.
Following is my Code. I am working on a Windows Service which looks for backup files in a particular folder. If it finds a new one it Picks that up move to an archive folder and Restore the database.
Since I am not using FileWatcher (i am using DirectoryInfo to check for new files) I need to schedule the windows service to keep checking the folder every 5 minutes.
Code:
protected override void OnStart(string[] args){
...
...
...
// Some Codes.
...
...
...
createOrderTimer = new System.Timers.Timer();
createOrderTimer.Elapsed += new ElapsedEventHandler( MoveToProcessed(processed) );
createOrderTimer.Interval = 300000; // 15 min
createOrderTimer.Enabled = true;
createOrderTimer.AutoReset = true;
createOrderTimer.Start();
}
private void MoveToProcessed(string processed){
...
...
...
// Some Codes.
...
...
...
}
I am getting Error CS0149 - Method name Expected.
-
May 23rd, 2019, 05:38 PM
#2
Re: Unable to pass Method as argument to ElapsedEventHandler.
You made the same mistake as the OP in the 12 year old thread. You need to provide the correct event method signature.
Since about VS2015, Visual Studio makes it easy for you with auto code completion. Simply type:
Code:
createOrderTimer.Elapsed +=
and press the TAB key a couple of times and VS will create the appropriate event handler for you and wire it up to the Elapsed event as well.
The missing puzzle piece is the object that is passed into the event handler is the 'this' parameter of the class where you have declared the timer. So add a string Path property to this class and inside the handler, cast the object parameter to your class. This allow you to then access the Path property.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|