rishi garg

rishi garg

  • NA
  • 1
  • 0

The Windows service application is not working properly

Mar 23 2007 10:22 AM
Hi there,

I am facing a strange problem related to windows service application. The problem is describe as below.

I have created a windows service application project using VS 2005. The application is scheduled to run at specified time interval. The application reads some of the variables from App.Config file. The application if I run as a console application, it runs perfectly and gives required output and also generates event log.

When we try to run the application as windows service it belaves abnormally and in the log we can see that the application starts again and again, but not completing the entire process.

A peace of code of OnStart event for our windows service is pasted below.

protected override void OnStart(string[] args)
{
            try
            {
                MainClass main = new MainClass();
                main.ReadConfigSettings();

                _timer = new System.Timers.Timer();

                ScheduleQuarterly("1", "1", "10:00 AM");
                _timer.Elapsed += new ElapsedEventHandler(TimerFired);
                //_timer.AutoReset = true;
                _timer.Enabled = true;
                _timer.Start();
            }
            catch (Exception ex)
            {
            }
        }

The peace of code of the TimerFired is also pasted below for your reference.

        private void TimerFired(object sender, ElapsedEventArgs e)
        {
            try
            {

<start process code goes here>

            }
            catch (Exception ex)
            {
            }
        }

Please response to it.

Regards,
Rishi


Answers (1)