Windo Service restart all the time

I have the following code to restart my service but it keeps on restarting in a loop ie OnStart keeps on firing...I have the following code to restart my service but it keeps on restarting in a loop ie OnStart keeps on firing...

Any suggestion?

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Diagnostics;using System.Linq;using System.ServiceProcess;using System.Text;using System.Data.SqlClient;using System.IO;//using Quartz;//using Quartz.Impl;//using Quartz.Impl.Triggers;using Gibraltar.Agent;using static test.Gateway.Gateway;using wyDay.Controls;using System.Threading;

namespace test.Gateway{

public partial class Service1 : ServiceBase { static AutomaticUpdaterBackend auBackend; // private static EventLog eventLog1; public const string ServiceName1 = "test.Gateway"; // wsSmallBiz.Service1 wsSmallBizService = new wsSmallBiz.Service1(); //string ExePath; //Stream myFile; /// <summary> /// Runs this instance. /// </summary> /// static bool CheckedForUpdate =false;

public void Run() {

Trace.TraceInformation("Run.."); OnStart(null); }

public Service1() {

Trace.TraceInformation("test.Gateway::Service instance started.."); ServiceName = ServiceName1;

//Setup logging this.AutoLog = true;

((ISupportInitialize) this.EventLog).BeginInit(); if (!EventLog.SourceExists(this.ServiceName)) { EventLog.CreateEventSource(this.ServiceName, "Application"); } ((ISupportInitialize) this.EventLog).EndInit();

this.EventLog.Source = this.ServiceName; this.EventLog.Log = "Application";

}

private void Gateway_LogIt(object sender, myEvent e) { switch (e.severity) { case 1://error Trace.TraceError(e.message);

break; case 2: //warning Trace.TraceWarning(e.message); break; case 3: Trace.TraceInformation(e.message); break; case -99: this.EventLog.WriteEntry("Gateway_LogIt::Fatal Exit", EventLogEntryType.Error,999); Trace.TraceInformation(e.message); Environment.Exit(1); break; default: Trace.TraceInformation(e.message); break; } }

protected override void OnStart(string[] args) {

auBackend = new AutomaticUpdaterBackend { //TODO: set a unique string. // For instance, "appname-companyname" GUID = "test.Gateway",

// With UpdateType set to Automatic, you're still in // charge of checking for updates, but the // AutomaticUpdaterBackend continues with the // downloading and extracting automatically. UpdateType = UpdateType.Automatic,

// We set the service name that will be used by wyUpdate // to restart this service on update success or failure. ServiceName = this.ServiceName };

this.EventLog.WriteEntry("OnStart..Running version[3.56]", EventLogEntryType.Information,123);

auBackend.ReadyToBeInstalled += auBackend_ReadyToBeInstalled; auBackend.UpdateSuccessful += auBackend_UpdateSuccessful; auBackend.CheckingFailed += AuBackend_CheckingFailed; auBackend.ExtractingFailed += AuBackend_ExtractingFailed; auBackend.UpdateFailed += AuBackend_UpdateFailed; ; auBackend.ProgressChanged += AuBackend_ProgressChanged; auBackend.UpdateAvailable += AuBackend_UpdateAvailable; auBackend.DownloadingFailed += AuBackend_DownloadingFailed; //TODO: use the failed events for logging & error reporting: // CheckingFailed, DownloadingFailed, ExtractingFailed, UpdateFailed

// Initialize() and AppLoaded() must be called after events have been set. // Note: If there's a pending update to be installed, wyUpdate will be // started, then it will talk back and say "ready to install, // you can close now" at which point your app will be closed. auBackend.Initialize(); auBackend.AppLoaded();

if (!auBackend.ClosingForInstall) { this.EventLog.WriteEntry("test.Gateway::!auBackend::No update found", EventLogEntryType.Information,12); // sees if you checked in the last 10 days, if not it rechecks

CheckEvery10Days(); //Note: Also, since this will be a service you should call // CheckEvery10Days() from an another thread (rather // than just at startup)

//TODO: do your normal service work try { Gateway.LogIt += Gateway_LogIt; Gateway.Start(); this.EventLog.WriteEntry("test.Gateway::auBackend::Service started", EventLogEntryType.Information, 100); Trace.TraceError("test.Gateway::auBackend::Service started"); //Trace.WriteLine("Schedule created.."); } catch (Exception ex) { this.EventLog.WriteEntry("OnStart::Exception::" + ex.ToString(), EventLogEntryType.Error, 1032); Trace.TraceError("OnStart::Exception::" + ex.Message); } }

}

private void AuBackend_DownloadingFailed(object sender, FailArgs e) { this.EventLog.WriteEntry(string.Format("AuBackend_DownloadingFailed...[{0}]", e.ToString()), EventLogEntryType.Warning, 1016); }

private void AuBackend_UpdateAvailable(object sender, EventArgs e) { this.EventLog.WriteEntry(string.Format("AuBackend_UpdateAvailable...[{0}]",e.ToString()), EventLogEntryType.Warning,1011); }

private void AuBackend_ProgressChanged(object sender, int progress) { if((progress % 5)==0) Trace.TraceError(string.Format("AuBackend_ProgressChanged...[{0}]", progress)); }

private void AuBackend_UpdateFailed(object sender, FailArgs e) { this.EventLog.WriteEntry("AuBackend_UpdateFailed..." + e.ErrorMessage, EventLogEntryType.Error,1075);

}

private void AuBackend_ExtractingFailed(object sender, FailArgs e) { this.EventLog.WriteEntry(string.Format("AuBackend_ExtractingFailed...Error[{0}]", e.ErrorMessage), EventLogEntryType.Error,1044); }

private void AuBackend_CheckingFailed(object sender, FailArgs e) { this.EventLog.WriteEntry(string.Format("AuBackend_CheckingFailed...Error[{0}]", e.ErrorMessage), EventLogEntryType.Error,1087); }

private void auBackend_UpdateSuccessful(object sender, SuccessArgs e) { Trace.TraceInformation("auBackend_UpdateSuccessful.."); this.EventLog.WriteEntry(string.Format("auBackend_UpdateSuccessful...v[{0}]", e.Version), EventLogEntryType.Information,1434); }

static void auBackend_ReadyToBeInstalled(object sender, EventArgs e) {

EventLog.WriteEntry("test.Gateway", "test.Gateway::auBackend_ReadyToBeInstalled" + auBackend.UpdateStepOn.ToString(), EventLogEntryType.Information,44);

if (auBackend.UpdateStepOn == UpdateStepOn.UpdateReadyToInstall) { //TODO: Delay the installation of the update until // it's appropriate for your app. EventLog.WriteEntry("test.Gateway", "UpdateReadyToInstall..going to install update..", EventLogEntryType.Information, 84); try { Gateway.ShutDown(); } catch (Exception ex) { EventLog.WriteEntry("test.Gateway", "Gateway.ShutDown()::Exception::" + ex.Message, EventLogEntryType.Information, 88); } EventLog.WriteEntry("test.Gateway", "Shutdown completed..going to install update..", EventLogEntryType.Information, 89);

Thread.Sleep(1000);

auBackend.InstallNow(); } else { EventLog.WriteEntry("test.Gateway", "Shutdown completed..going to install update..", EventLogEntryType.Information, 1082);

} }

static void CheckEvery10Days() { EventLog.WriteEntry("test.Gateway", string.Format("Start checking for updated[{0}]..", auBackend.LastCheckDate), EventLogEntryType.Information,321); if ((DateTime.Now - auBackend.LastCheckDate).TotalMinutes > 2 && auBackend.UpdateStepOn == UpdateStepOn.Nothing) { EventLog.WriteEntry("test.Gateway", "Check for updated..ForceCheckForUpdate", EventLogEntryType.Information,654); CheckedForUpdate = true; auBackend.ForceCheckForUpdate(); } }

protected override void OnStop() { Trace.TraceInformation("OnStop..."); this.EventLog.WriteEntry("In OnStop.."); try { Trace.WriteLine("OnStop.."); Gateway.ShutDown(); } catch (Exception ex) { this.EventLog.WriteEntry("In OnStop::Exception::" + ex.Message, EventLogEntryType.Error,1232); Trace.WriteLine("OnStop::Exception::" + ex.Message.ToString()); } this.EventLog.WriteEntry("..OnStop"); Trace.TraceInformation("..OnStop"); }

private void InitializeComponent() {;

} }}

Sorry, we don't provide debugging services. Attach a debugger to your service and step through the code until you find your bug.