473,378 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Time in Service

I'm creating a service and am using a timer in it. When the service starts
I enable the timer, and then in the timer elasped event, I'm disabling it
(this.srvcTimer.Enabled = false) so the timer event doesn't fire while I'm
already in it. At the end of the timer elapsed event I re-enable it.
However, while running in the debugger, the event never fires. If I comment
out the line disabling the timer in the elapsed event, the event fires. I'm
not quite sure what I'm doing wrong if anything.

Here's the code in question, and the appropriate lines in the elapsed event
are commented... the event in the last bit of code at the bottom...

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Reflection;
using System.Configuration;

using System.Xml;
using System.Xml.XPath;
using Dell.WWOps.GlobalShip.External;

namespace DELL_QWatcher
{
// TODO: learn how to create class and/or structure for holding config data
from INI

public class DELL_QWatcher : ServiceBase
{
private System.Timers.Timer srvcTimer;

/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public DELL_QWatcher()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call
}

// The main entry point for the process
static void Main()
{
ServiceBase[] ServicesToRun;

// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new
Service1(), new MySecondUserService()};
//
ServicesToRun = new ServiceBase[] { new DELL_QWatcher() };

ServiceBase.Run(ServicesToRun);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.srvcTimer = new System.Timers.Timer();
((System.ComponentModel.ISupportInitialize)(this.s rvcTimer)).BeginInit();
//
// srvcTimer
//
this.srvcTimer.Interval = 5000;
this.srvcTimer.Elapsed += new
System.Timers.ElapsedEventHandler(this.srvcTimer_E lapsed);
//
// DELL_QWatcher
//
this.ServiceName = "DELL_QWatcher";
((System.ComponentModel.ISupportInitialize)(this.s rvcTimer)).EndInit();

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
// INI processes service configuration stuff...
// this.srvcTimer.Interval =
Convert.ToDouble(ConfigurationSettings.AppSettings["interval"].ToString());
this.srvcTimer.Enabled = true;
}

/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
this.srvcTimer.Enabled = false;
}

private void srvcTimer_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
// stop the timer, so we're no re-entrant
// if this is commented out, the event fires as expected. However, if
it's not commented out, this event never fires...
// this.srvcTimer.Enabled = false;

// TODO: add processing code here...
// breakpoint goes here
GlobalShipSystem oGS = GlobalShipSystem.Instance;
XPathNavigator nav = oGS.GetNextOrder();

if (nav != null)
{

}

// re-start the time
// this.srvcTimer.Enabled = true;
}

}
}
Nov 17 '05 #1
0 1101

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeff User | last post by:
Here is what I have and what I would like to do: I am building a web client application. I add a web reference to some web service server to my project so that now I can call the web service. A...
7
by: José Joye | last post by:
On all my Windows Services (written in C# and for some of them in MC++), I got from time to time crashes at startup (1 out of 10 startup). It occurs really at the time I click on the "Start...
2
by: Jeff User | last post by:
Here is what I have and what I would like to do: I am building a web client application. I add a web reference to some web service server to my project so that now I can call the web service. A...
11
by: Jason | last post by:
Hi I have a "problem" i have got a ASP.NET application. in this application i have included logging. in the logging i have logged how many seconds it takes for this application to fully load....
0
by: Temporary | last post by:
C# Web Service in IIS Stops Connecting to Oracle (via ADO.NET) Over Time I have a Web Service, written in C#, published on a Windows XT Web Server under IIS, which repeatedly connects to an...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.