Urgent Window Service Error

Posted by Nismeh under .NET Framework on 10/1/2013 | Points: 10 | Views : 1074 | Status : [Member] | Replies : 3
Hi,

I am getting an error saying

No Overload for 'OnTimedEvent' matches delegate 'System.Timers.ElapsedEventHandler' at timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

Can anyone plz help me to resolve this?


using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Timers;
namespace WinServiceSample
{
public partial class ScheduledService : ServiceBase
{
Timer timer = new Timer();
public ScheduledService()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
TraceService("Start Service");
timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
timer.Interval = 60000;
timer.Enabled = true;
}
public void OnTimedEvent(object source, ElapsedEventHandler e)
{
TraceService("Another entry at " + DateTime.Now);
}
private void TraceService(string content)
{
FileStream fs = new FileStream(@"d:\ScheduledService.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine(content);
sw.Flush();
sw.Close();
}

protected override void OnStop()
{
timer.Enabled = false;
TraceService("Stopping Service");
}
}
}

IT KNOWLEDGE IS APPLIED KNOWLEDGE
So Just Do It



Responses

Posted by: Bandi on: 10/1/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer this link
http://social.msdn.microsoft.com/Forums/en-US/6ad75ef6-b2f4-41b7-ae79-1f01471f3478/timers-error

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Nismeh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 10/1/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
http://code-creeper.appspot.com/
http://stackoverflow.com/questions/4376411/c-sharp-timer-getting-the-method-name-expected-error

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Nismeh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 10/1/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Have you solved the above error?
If yes "Mark as Answer" ; Otherwise post us back

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Nismeh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response