Getting an error when starting a Windows Service.  
Author Message
Bulldog.NET





PostPosted: Visual C# General, Getting an error when starting a Windows Service. Top

Hi

I have a windows service that I have installed in the machine and its using a timer like the code below to upload files from one location into another every 40 seconds, some how when I start the service I get the following error :-


The FileUpload service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Perfomance Logs and Alerts service.

What could be the problem, the service is using the Local System Account, here is my code below.


System.Timers.Timer iBaseTimer = new System.Timers.Timer();
protected override void OnStart(string[] args)
{
iBaseTimer.Interval = 40000;
iBaseTimer.Enabled =
true;
iBaseTimer.Elapsed +=
new ElapsedEventHandler(time_Elapsed);
}
protected override void OnStop()
{
iBaseTimer.Enabled =
false;
}
private void time_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try

{
//Do operation

}
catch (Exception ex)
{
if (!EventLog.SourceExists("FileUpload"))
EventLog.CreateEventSource("FileUpload", "Application");
EventLog iBaseLog = new EventLog();
iBaseLog.Source =
"FileUpload";
iBaseLog.Wri****try(message,
EventLogEntryType.Error);
}
}

Your help will be highly appreciated.




Visual C#4  
 
 
Sudeesh





PostPosted: Visual C# General, Getting an error when starting a Windows Service. Top

clear the app log and call iBaseTimer.Start at the end of OnStart method.

 

Regards,
  Sudeesh


 
 
Sibusiso





PostPosted: Visual C# General, Getting an error when starting a Windows Service. Top

Thanks man, it works.