473,321 Members | 1,916 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,321 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 4340
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.