Skip to content

The Windows service application is not working properly

rishi garg

Asked Mar 23, 2007, 6:22 AM EDT1 answer
Share
LinkedInX
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.

C#
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

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    not sure why this is happening, but I recommend that you use the windows scheduler to schedule your service, because this is more common practice.  Have the scheduler run a batch file start.bat that calls :

    net start <name of your service>


    best,

    -Mike
    0