Hello all. We have about 10 Window's services that we wrote in c#. We use
them to process row's that we have queued up in various SQL tables.
The services seem to hang at least once in any given 24 hour period. Once we
reset the service, it goes about its processing business until the next time
it hangs. We are wondering if the hanging problem is due to a load issue
(too many windows services on a single machine), a code flaw, or an inherent
c# bug? We used to write NT services in VB6 using the ntsvc.ocx. Those
services never hung. I'm wondering if we are going to have to rewrite all of
our c# services in old school vb6. I've included the Service code
below...any help would be much appreciated.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Configuration;
namespace IAR_Service
{
public class IAR : System.ServiceProcess.ServiceBase
{
private System.Timers.Timer tmrWinService;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public IAR()
{
// 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()
{
System.ServiceProcess.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 System.ServiceProcess.ServiceBase[] { new IAR() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tmrWinService = new System.Timers.Timer();
((System.ComponentModel.ISupportInitialize)(this.t mrWinService)).BeginInit()
;
//
// tmrWinService
//
//this.tmrWinService.Enabled = true;
this.tmrWinService.Interval = 20000;
this.tmrWinService.Elapsed += new
System.Timers.ElapsedEventHandler(this.tmrWinServi ce_Elapsed);
//
// IAR
//
this.AutoLog = false;
this.CanPauseAndContinue = true;
this.ServiceName = "IAR";
((System.ComponentModel.ISupportInitialize)(this.t mrWinService)).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)
{
// TODO: Add code here to start your service.
tmrWinService.Enabled = true;
tmrWinService.AutoReset = true;
tmrWinService.Start();
//see if log exists. if not, create
if (!EventLog.SourceExists("IAR-Service")) EventLog.CreateEventSource("",
"IAR-Service", ".");
//log
EventLog log = new EventLog();
log.Log = "IAR-Service";
log.Source = "WinServiceIAR.OnStart";
log.WriteEntry("Starting IAR windows Service",
EventLogEntryType.Information);
log.Dispose();
}
/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your
service.
tmrWinService.Enabled = true;
tmrWinService.AutoReset = true;
tmrWinService.Stop();
//see if log exists. if not, create
if (!EventLog.SourceExists("IAR-Service")) EventLog.CreateEventSource("",
"IAR-Service", ".");
//log
EventLog log = new EventLog();
log.Log = "IAR-Service";
log.Source = "WinServiceIAR.OnStop";
log.WriteEntry("Stopping IAR windows Service",
EventLogEntryType.Information);
log.Dispose();
}
private void tmrWinService_Elapsed(Object sender,
System.Timers.ElapsedEventArgs e)
{
this.tmrWinService.Stop();
try
{
UserServices oUser = new UserServices();
ScriptingTelnet st = new ScriptingTelnet();
//CALL
oUser.processIAR();
}
catch (Exception err)
{
//see if log exists. if not, create
if (!EventLog.SourceExists("IAR-Service"))
EventLog.CreateEventSource("", "IAR-Service", ".");
//log
EventLog log = new EventLog();
log.Log = "IAR-Service";
log.Source = "WinServiceIAR.tmrWinService_Elapsed";
log.WriteEntry(err.Message.ToString(), EventLogEntryType.Error);
log.Dispose();
}
finally
{
this.tmrWinService.Start();
}
}
}
} 3 4353
What's the purpose of this?
ScriptingTelnet st = new ScriptingTelnet();
Willy.
"Jacob Crossley" <ja***********@hotmail.com> wrote in message
news:WY***************@fe25.usenetserver.com... Hello all. We have about 10 Window's services that we wrote in c#. We use them to process row's that we have queued up in various SQL tables.
The services seem to hang at least once in any given 24 hour period. Once we reset the service, it goes about its processing business until the next time it hangs. We are wondering if the hanging problem is due to a load issue (too many windows services on a single machine), a code flaw, or an inherent c# bug? We used to write NT services in VB6 using the ntsvc.ocx. Those services never hung. I'm wondering if we are going to have to rewrite all of our c# services in old school vb6. I've included the Service code below...any help would be much appreciated.
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.ServiceProcess; using System.Configuration;
namespace IAR_Service { public class IAR : System.ServiceProcess.ServiceBase { private System.Timers.Timer tmrWinService; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null;
public IAR() { // 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() { System.ServiceProcess.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 System.ServiceProcess.ServiceBase[] { new IAR() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.tmrWinService = new System.Timers.Timer();
((System.ComponentModel.ISupportInitialize)(this.t mrWinService)).BeginInit() ; // // tmrWinService // //this.tmrWinService.Enabled = true; this.tmrWinService.Interval = 20000; this.tmrWinService.Elapsed += new System.Timers.ElapsedEventHandler(this.tmrWinServi ce_Elapsed); // // IAR // this.AutoLog = false; this.CanPauseAndContinue = true; this.ServiceName = "IAR";
((System.ComponentModel.ISupportInitialize)(this.t mrWinService)).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) { // TODO: Add code here to start your service. tmrWinService.Enabled = true; tmrWinService.AutoReset = true; tmrWinService.Start(); //see if log exists. if not, create if (!EventLog.SourceExists("IAR-Service")) EventLog.CreateEventSource("", "IAR-Service", "."); //log EventLog log = new EventLog(); log.Log = "IAR-Service"; log.Source = "WinServiceIAR.OnStart"; log.WriteEntry("Starting IAR windows Service", EventLogEntryType.Information); log.Dispose(); }
/// <summary> /// Stop this service. /// </summary> protected override void OnStop() { // TODO: Add code here to perform any tear-down necessary to stop your service. tmrWinService.Enabled = true; tmrWinService.AutoReset = true; tmrWinService.Stop(); //see if log exists. if not, create if (!EventLog.SourceExists("IAR-Service")) EventLog.CreateEventSource("", "IAR-Service", "."); //log EventLog log = new EventLog(); log.Log = "IAR-Service"; log.Source = "WinServiceIAR.OnStop"; log.WriteEntry("Stopping IAR windows Service", EventLogEntryType.Information); log.Dispose(); }
private void tmrWinService_Elapsed(Object sender, System.Timers.ElapsedEventArgs e) { this.tmrWinService.Stop(); try { UserServices oUser = new UserServices(); ScriptingTelnet st = new ScriptingTelnet(); //CALL oUser.processIAR();
} catch (Exception err) { //see if log exists. if not, create if (!EventLog.SourceExists("IAR-Service")) EventLog.CreateEventSource("", "IAR-Service", "."); //log EventLog log = new EventLog(); log.Log = "IAR-Service"; log.Source = "WinServiceIAR.tmrWinService_Elapsed"; log.WriteEntry(err.Message.ToString(), EventLogEntryType.Error); log.Dispose(); } finally { this.tmrWinService.Start(); } } } }
That just instantiates another class in the sln....Its a custom class that
adds and removes people from an acl on a router to restrict/permit internet
access at our ISP...I could include that code if you'd like, but all of our
services hang, regardless of what they do in the worker classes...I'd
propose that the service would hang even if it called a class that wrote
'hello world' to a text file.
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl... What's the purpose of this?
ScriptingTelnet st = new ScriptingTelnet();
Willy.
"Jacob Crossley" <ja***********@hotmail.com> wrote in message news:WY***************@fe25.usenetserver.com... Hello all. We have about 10 Window's services that we wrote in c#. We
use them to process row's that we have queued up in various SQL tables.
The services seem to hang at least once in any given 24 hour period.
Once we reset the service, it goes about its processing business until the next time it hangs. We are wondering if the hanging problem is due to a load issue (too many windows services on a single machine), a code flaw, or an inherent c# bug? We used to write NT services in VB6 using the ntsvc.ocx. Those services never hung. I'm wondering if we are going to have to rewrite
all of our c# services in old school vb6. I've included the Service code below...any help would be much appreciated.
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.ServiceProcess; using System.Configuration;
namespace IAR_Service { public class IAR : System.ServiceProcess.ServiceBase { private System.Timers.Timer tmrWinService; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null;
public IAR() { // 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() { System.ServiceProcess.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 System.ServiceProcess.ServiceBase[] { new IAR() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.tmrWinService = new System.Timers.Timer();
((System.ComponentModel.ISupportInitialize)(this.t mrWinService)).BeginInit() ; // // tmrWinService // //this.tmrWinService.Enabled = true; this.tmrWinService.Interval = 20000; this.tmrWinService.Elapsed += new System.Timers.ElapsedEventHandler(this.tmrWinServi ce_Elapsed); // // IAR // this.AutoLog = false; this.CanPauseAndContinue = true; this.ServiceName = "IAR";
((System.ComponentModel.ISupportInitialize)(this.t mrWinService)).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) { // TODO: Add code here to start your service. tmrWinService.Enabled = true; tmrWinService.AutoReset = true; tmrWinService.Start(); //see if log exists. if not, create if (!EventLog.SourceExists("IAR-Service")) EventLog.CreateEventSource("", "IAR-Service", "."); //log EventLog log = new EventLog(); log.Log = "IAR-Service"; log.Source = "WinServiceIAR.OnStart"; log.WriteEntry("Starting IAR windows Service", EventLogEntryType.Information); log.Dispose(); }
/// <summary> /// Stop this service. /// </summary> protected override void OnStop() { // TODO: Add code here to perform any tear-down necessary to stop your service. tmrWinService.Enabled = true; tmrWinService.AutoReset = true; tmrWinService.Stop(); //see if log exists. if not, create if (!EventLog.SourceExists("IAR-Service")) EventLog.CreateEventSource("", "IAR-Service", "."); //log EventLog log = new EventLog(); log.Log = "IAR-Service"; log.Source = "WinServiceIAR.OnStop"; log.WriteEntry("Stopping IAR windows Service", EventLogEntryType.Information); log.Dispose(); }
private void tmrWinService_Elapsed(Object sender, System.Timers.ElapsedEventArgs e) { this.tmrWinService.Stop(); try { UserServices oUser = new UserServices(); ScriptingTelnet st = new ScriptingTelnet(); //CALL oUser.processIAR();
} catch (Exception err) { //see if log exists. if not, create if (!EventLog.SourceExists("IAR-Service")) EventLog.CreateEventSource("", "IAR-Service", "."); //log EventLog log = new EventLog(); log.Log = "IAR-Service"; log.Source = "WinServiceIAR.tmrWinService_Elapsed"; log.WriteEntry(err.Message.ToString(), EventLogEntryType.Error); log.Dispose(); } finally { this.tmrWinService.Start(); } } } }
Willy.
"Jacob Crossley" <ja***********@hotmail.com> wrote in message
news:il***************@fe25.usenetserver.com... That just instantiates another class in the sln....Its a custom class that adds and removes people from an acl on a router to restrict/permit internet access at our ISP...I could include that code if you'd like, but all of our services hang, regardless of what they do in the worker classes...I'd propose that the service would hang even if it called a class that wrote 'hello world' to a text file.
No need to check this with a simple "hello world" service :-),I have a
couple of services ,running for weeks now, performing some tasks at regular
intervals using System.Threading.Timer.
Is it possible that this custom class takes longer than the interval? And,
when it's the possibility exists, are you sure that, your custom class is
threadsafe, and there is no possibility for race conditions leading to
deadlocks?
I suggest you watch some resources like # of handles, # of run-able threads
when the service runs and when it hangs.
Another thing you can do is attach a debugger to your hung service and try
to find out where it hangs.
Willy. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jacob Crossley |
last post by:
Hello all. We have about 10 Window's services that we wrote in c#. We use
them to process row's that we have queued up in various SQL tables.
The services seem to hang at least once in any given...
|
by: Kris |
last post by:
I have a Windows Service in C# talking to a serial port and using Remoting.
It also uses several COM objects. On customer's computer the service will
occassionally hang somewhere - the service...
|
by: Andrea Vincenzi |
last post by:
Help me please, I'm totally stuck!
My Visual Studio 2003 debugger stopped working after I installed
Windows XP Service Pack 2. Here is what happens (with any project,
even a "Hello, world"...
|
by: Steven De Smet |
last post by:
Hello,
This is my first post. I searched on the internet for answers but I was unable to solve my problem. So I hope that you guy's can help me with my VB.NET problem
I tried to create a...
|
by: Ashish Khandelwal |
last post by:
I have a Windows Service in C# talking to a serial port and using
Remoting.
It also uses several COM objects. On server the service will
occassionally hang somewhere - the service still shows on a...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |