473,395 Members | 1,343 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,395 software developers and data experts.

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.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();
}
}
}
}
Nov 16 '05 #1
3 4356
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();
}
}
}
}

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**************@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();
}
}
}
}


Nov 16 '05 #3

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.
Nov 16 '05 #4

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

Similar topics

15
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...
4
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...
5
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"...
4
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...
7
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...
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: 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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.