private void onTimerElapsed(object sender, System.Timers.ElapsedEventArgs e) { //Event handler for self timed operation try { if (this.mStartup) { //Set startup condition- create utility service this.mStartup = false; this.mTimer.Interval = getTimerInterval(); initServices(); } if (!this.mShutdown) { //Run the service for (int i = 0; i < this.mSvcs.Length; i++) { FileMgr svc = this.mSvcs[i]; svc.Execute(); } for (int j = 0; j < this.mFTPSvcs.Length; j++) { FTPMgr ftp = this.mFTPSvcs[j]; ftp.Execute(); } } else { //Shutdown condition this.mTimer.Enabled = false; } } catch (ApplicationException ex) { throw ex; } catch (Exception ex) { reportError(new ApplicationException("Unexpected error in timer interval operations.", ex), false, true); } }
protected override void OnStart(string[] args) { //Set things in motion so your service can do its work try { //Timed or one shot if (this.mUseTimer) { this.mStartup = true; this.mTimer.Interval = 100; this.mTimer.Enabled = true; } else { initServices(); for (int i = 0; i < this.mSvcs.Length; i++) { FileMgr svc = this.mSvcs[i]; svc.Execute(); } for (int j = 0; j < this.mFTPSvcs.Length; j++) { FTPMgr ftp = this.mFTPSvcs[j]; ftp.Execute(); } } } catch (Exception ex) { reportError(new ApplicationException("Unexpected error in OnStart.", ex), false, true); } }