473,748 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

windows Service Hangs

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.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Diagnost ics;
using System.ServiceP rocess;
using System.Configur ation;

namespace IAR_Service
{
public class IAR : System.ServiceP rocess.ServiceB ase
{
private System.Timers.T imer tmrWinService;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public IAR()
{
// This call is required by the Windows.Forms Component Designer.
InitializeCompo nent();

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

// The main entry point for the process
static void Main()
{
System.ServiceP rocess.ServiceB ase[] 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.ServiceP rocess.ServiceB ase[] {new
Service1(), new MySecondUserSer vice()};
//
ServicesToRun = new System.ServiceP rocess.ServiceB ase[] { new IAR() };

System.ServiceP rocess.ServiceB ase.Run(Service sToRun);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.tmrWinServ ice = new System.Timers.T imer();

((System.Compon entModel.ISuppo rtInitialize)(t his.tmrWinServi ce)).BeginInit( )
;
//
// tmrWinService
//
//this.tmrWinServ ice.Enabled = true;
this.tmrWinServ ice.Interval = 20000;
this.tmrWinServ ice.Elapsed += new
System.Timers.E lapsedEventHand ler(this.tmrWin Service_Elapsed );
//
// IAR
//
this.AutoLog = false;
this.CanPauseAn dContinue = true;
this.ServiceNam e = "IAR";

((System.Compon entModel.ISuppo rtInitialize)(t his.tmrWinServi ce)).EndInit();

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
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.E nabled = true;
tmrWinService.A utoReset = true;
tmrWinService.S tart();
//see if log exists. if not, create
if (!EventLog.Sour ceExists("IAR-Service")) EventLog.Create EventSource("",
"IAR-Service", ".");
//log
EventLog log = new EventLog();
log.Log = "IAR-Service";
log.Source = "WinServiceIAR. OnStart";
log.WriteEntry( "Starting IAR windows Service",
EventLogEntryTy pe.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.E nabled = true;
tmrWinService.A utoReset = true;
tmrWinService.S top();
//see if log exists. if not, create
if (!EventLog.Sour ceExists("IAR-Service")) EventLog.Create EventSource("",
"IAR-Service", ".");
//log
EventLog log = new EventLog();
log.Log = "IAR-Service";
log.Source = "WinServiceIAR. OnStop";
log.WriteEntry( "Stopping IAR windows Service",
EventLogEntryTy pe.Information) ;
log.Dispose();
}

private void tmrWinService_E lapsed(Object sender,
System.Timers.E lapsedEventArgs e)
{
this.tmrWinServ ice.Stop();
try
{
UserServices oUser = new UserServices();
ScriptingTelnet st = new ScriptingTelnet ();
//CALL
oUser.processIA R();

}
catch (Exception err)
{
//see if log exists. if not, create
if (!EventLog.Sour ceExists("IAR-Service"))
EventLog.Create EventSource("", "IAR-Service", ".");
//log
EventLog log = new EventLog();
log.Log = "IAR-Service";
log.Source = "WinServiceIAR. tmrWinService_E lapsed";
log.WriteEntry( err.Message.ToS tring(), EventLogEntryTy pe.Error);
log.Dispose();
}
finally
{
this.tmrWinServ ice.Start();
}
}
}
}
Nov 16 '05 #1
3 4413
What's the purpose of this?

ScriptingTelnet st = new ScriptingTelnet ();

Willy.

"Jacob Crossley" <ja***********@ hotmail.com> wrote in message
news:WY******** *******@fe25.us enetserver.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.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Diagnost ics;
using System.ServiceP rocess;
using System.Configur ation;

namespace IAR_Service
{
public class IAR : System.ServiceP rocess.ServiceB ase
{
private System.Timers.T imer tmrWinService;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public IAR()
{
// This call is required by the Windows.Forms Component Designer.
InitializeCompo nent();

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

// The main entry point for the process
static void Main()
{
System.ServiceP rocess.ServiceB ase[] 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.ServiceP rocess.ServiceB ase[] {new
Service1(), new MySecondUserSer vice()};
//
ServicesToRun = new System.ServiceP rocess.ServiceB ase[] { new IAR() };

System.ServiceP rocess.ServiceB ase.Run(Service sToRun);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.tmrWinServ ice = new System.Timers.T imer();

((System.Compon entModel.ISuppo rtInitialize)(t his.tmrWinServi ce)).BeginInit( )
;
//
// tmrWinService
//
//this.tmrWinServ ice.Enabled = true;
this.tmrWinServ ice.Interval = 20000;
this.tmrWinServ ice.Elapsed += new
System.Timers.E lapsedEventHand ler(this.tmrWin Service_Elapsed );
//
// IAR
//
this.AutoLog = false;
this.CanPauseAn dContinue = true;
this.ServiceNam e = "IAR";

((System.Compon entModel.ISuppo rtInitialize)(t his.tmrWinServi ce)).EndInit();

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
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.E nabled = true;
tmrWinService.A utoReset = true;
tmrWinService.S tart();
//see if log exists. if not, create
if (!EventLog.Sour ceExists("IAR-Service"))
EventLog.Create EventSource("",
"IAR-Service", ".");
//log
EventLog log = new EventLog();
log.Log = "IAR-Service";
log.Source = "WinServiceIAR. OnStart";
log.WriteEntry( "Starting IAR windows Service",
EventLogEntryTy pe.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.E nabled = true;
tmrWinService.A utoReset = true;
tmrWinService.S top();
//see if log exists. if not, create
if (!EventLog.Sour ceExists("IAR-Service"))
EventLog.Create EventSource("",
"IAR-Service", ".");
//log
EventLog log = new EventLog();
log.Log = "IAR-Service";
log.Source = "WinServiceIAR. OnStop";
log.WriteEntry( "Stopping IAR windows Service",
EventLogEntryTy pe.Information) ;
log.Dispose();
}

private void tmrWinService_E lapsed(Object sender,
System.Timers.E lapsedEventArgs e)
{
this.tmrWinServ ice.Stop();
try
{
UserServices oUser = new UserServices();
ScriptingTelnet st = new ScriptingTelnet ();
//CALL
oUser.processIA R();

}
catch (Exception err)
{
//see if log exists. if not, create
if (!EventLog.Sour ceExists("IAR-Service"))
EventLog.Create EventSource("", "IAR-Service", ".");
//log
EventLog log = new EventLog();
log.Log = "IAR-Service";
log.Source = "WinServiceIAR. tmrWinService_E lapsed";
log.WriteEntry( err.Message.ToS tring(), EventLogEntryTy pe.Error);
log.Dispose();
}
finally
{
this.tmrWinServ ice.Start();
}
}
}
}

Nov 16 '05 #2
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******** ******@TK2MSFTN GP09.phx.gbl...
What's the purpose of this?

ScriptingTelnet st = new ScriptingTelnet ();

Willy.

"Jacob Crossley" <ja***********@ hotmail.com> wrote in message
news:WY******** *******@fe25.us enetserver.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.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Diagnost ics;
using System.ServiceP rocess;
using System.Configur ation;

namespace IAR_Service
{
public class IAR : System.ServiceP rocess.ServiceB ase
{
private System.Timers.T imer tmrWinService;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public IAR()
{
// This call is required by the Windows.Forms Component Designer.
InitializeCompo nent();

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

// The main entry point for the process
static void Main()
{
System.ServiceP rocess.ServiceB ase[] 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.ServiceP rocess.ServiceB ase[] {new
Service1(), new MySecondUserSer vice()};
//
ServicesToRun = new System.ServiceP rocess.ServiceB ase[] { new IAR() };

System.ServiceP rocess.ServiceB ase.Run(Service sToRun);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.tmrWinServ ice = new System.Timers.T imer();

((System.Compon entModel.ISuppo rtInitialize)(t his.tmrWinServi ce)).BeginInit( ) ;
//
// tmrWinService
//
//this.tmrWinServ ice.Enabled = true;
this.tmrWinServ ice.Interval = 20000;
this.tmrWinServ ice.Elapsed += new
System.Timers.E lapsedEventHand ler(this.tmrWin Service_Elapsed );
//
// IAR
//
this.AutoLog = false;
this.CanPauseAn dContinue = true;
this.ServiceNam e = "IAR";

((System.Compon entModel.ISuppo rtInitialize)(t his.tmrWinServi ce)).EndInit();
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
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.E nabled = true;
tmrWinService.A utoReset = true;
tmrWinService.S tart();
//see if log exists. if not, create
if (!EventLog.Sour ceExists("IAR-Service"))
EventLog.Create EventSource("",
"IAR-Service", ".");
//log
EventLog log = new EventLog();
log.Log = "IAR-Service";
log.Source = "WinServiceIAR. OnStart";
log.WriteEntry( "Starting IAR windows Service",
EventLogEntryTy pe.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.E nabled = true;
tmrWinService.A utoReset = true;
tmrWinService.S top();
//see if log exists. if not, create
if (!EventLog.Sour ceExists("IAR-Service"))
EventLog.Create EventSource("",
"IAR-Service", ".");
//log
EventLog log = new EventLog();
log.Log = "IAR-Service";
log.Source = "WinServiceIAR. OnStop";
log.WriteEntry( "Stopping IAR windows Service",
EventLogEntryTy pe.Information) ;
log.Dispose();
}

private void tmrWinService_E lapsed(Object sender,
System.Timers.E lapsedEventArgs e)
{
this.tmrWinServ ice.Stop();
try
{
UserServices oUser = new UserServices();
ScriptingTelnet st = new ScriptingTelnet ();
//CALL
oUser.processIA R();

}
catch (Exception err)
{
//see if log exists. if not, create
if (!EventLog.Sour ceExists("IAR-Service"))
EventLog.Create EventSource("", "IAR-Service", ".");
//log
EventLog log = new EventLog();
log.Log = "IAR-Service";
log.Source = "WinServiceIAR. tmrWinService_E lapsed";
log.WriteEntry( err.Message.ToS tring(), EventLogEntryTy pe.Error);
log.Dispose();
}
finally
{
this.tmrWinServ ice.Start();
}
}
}
}


Nov 16 '05 #3

Willy.

"Jacob Crossley" <ja***********@ hotmail.com> wrote in message
news:il******** *******@fe25.us enetserver.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.Threadin g.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.
Nov 16 '05 #4

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

Similar topics

15
478
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 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...
4
9022
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 still shows on a Task Manager list. In Services it says it is still running. However there is no way to stop it other than by rebooting the whole computer. No exception (including non-CLS) is ever generated. I added a separate System.Timers.Timer...
5
2418
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" message): the first time I open a project and try to start it in debug mode, Visual Studio hangs before executing the first line of code. The only way to stop it is to kill the process using the Task Manager. If I open the same project a second time and...
4
8845
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 windows service that converts MS Word Files into .PDF files and after that we want to zip the .PDF files. Our code: Protected Overrides Sub OnStart(ByVal args() As String) ' Add code here to start your service. This method should set...
7
3215
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 Task Manager list. In Services it says it is still running. However there is no way to stop it other than by rebooting the whole computer. No exception (including non-CLS) is ever generated. I added a separate System.Timers.Timer
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.