473,597 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Windows service hangs

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.T imer
which
detects that the main thread stopped working. I was trying to stop it
by
using System.ServiceP rocess.ServiceC ontroller.Stop( ) which didn't
work. I
tried to do process.Kill() which also doesn't work (and no exception).
Is
there a bug in framework somewhere. I don't even hope to find out why
it
hangs but if I could just kill it that would solve the problem since I
have
another Service which would bring it up. I'll be greatful for any
ideas.
Dec 19 '07 #1
7 3199
Is there a bug in framework somewhere.
If this was my best code ever, my assumption would be that I'm doing
something wrong.
I don't even hope to find out why it hangs but if I could just kill it that would solve the problem since I
have another Service which would bring it up.
Ouch. I'd be wanting to know why... even if it was as simple as adding
a trace so I know what the thread(s) was (were) last doing .

It isn't exactly entry-level stuff, but if that fails, perhaps this is
a job for windbg / sos [assist]?

Marc

Dec 19 '07 #2
If this was my best code ever, my assumption would be that I'm doing
something wrong.

I read that again and realised it could be taken in two ways; I didn't
mean it in the derogatory way: more *even* if I was absolutely
confident that my code was right, I'd still suspect that I had gotten
something wrong somewhere that was messing this up.

Yes, the framework and Win32 do (both individually and in combination)
have bugs and features, but I'd try to rule out PEBKAC first.

Marc
Dec 19 '07 #3
One more thing, what would be the reason that i could not stop my
service, and there was only one way left which was reboot the system?
any idea plesae...

Dec 19 '07 #4
I'm assuming that you have tried killing the process from task manager
(you mention process.Kill(.. .); I interpret that as meaning "through
code")?

If you have a service that resists "kill", you're into some gnarly
hardcore debugging... sorry...

Marc
Dec 19 '07 #5
On Dec 19, 2:24 pm, Ashish Khandelwal <AKhandelwal.in ...@gmail.com>
wrote:
One more thing, what would be the reason that i could not stop my
service, and there was only one way left which was reboot the system?
any idea plesae...
You said that you are using multiple threads, so have you synchronized
objects between threads ? Try to use Monitor class in C#
Also, when dealing with windows service, use try catch block at all
necessary places, with strong logging facility. By logging, I mean to
say that you should know where the exception occurred and complete
stack trace of the Exception.
With this log, you can find the root cause for your problem and then
fix it.
I think you have changed code in existing windows service ? Am I
right ?

I would like to help you furthure, but for that I need the complete
log when the service "hangs". If you can provide that, it would be
helpful.
Dec 19 '07 #6
"Ashish Khandelwal" <AK************ ***@gmail.comwr ote in message
news:9f******** *************** ***********@e10 g2000prf.google groups.com...
>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.T imer
which
detects that the main thread stopped working. I was trying to stop it
by
using System.ServiceP rocess.ServiceC ontroller.Stop( ) which didn't
work. I
tried to do process.Kill() which also doesn't work (and no exception).
Is
there a bug in framework somewhere. I don't even hope to find out why
it
hangs but if I could just kill it that would solve the problem since I
have
another Service which would bring it up. I'll be greatful for any
ideas.

Attach a debugger to the hung service and inspect the stacks. My guess is
that you have deadlocked.
The reason (one of) you can't stop a service is that the service doesn't
react to a Stop request from the SCM, the SCM puts the service in a
"pending" stopped state and waits for the "Stopped" state indication from
the service, which never arrives. In this state the SCM can't do anything
further with the service, killing the service process doesn't help either,
the SCM has lost control over the service, all you can do is reboot :-(

Willy.

Dec 19 '07 #7
if a racecondition occurs its not certain that your program knows
about it, but I did manage to stop the process by stopping the service
(it didnt stop) and then killing the process by hand in task manager,
this was in my case caused by not joining threads if I remeber
correctly. have not tried .kill, but .abort from code (just to see
what happens), and yes if lucky try/catch might get it (the error), in
my case when it (the servvice) didnt start I just got a silly mess in
eventlig that id didnt start in 3000ms or something... found a
debugging "help" free from aimes (I think hes called that) that helpt
me out.

Havent tred debugging any other way but the previus posters seems to
have som expreience, just get a idea of where it stopped cold could be
a great help.

//CY
Dec 19 '07 #8

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

Similar topics

3
4405
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
9003
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
2400
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
8818
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...
0
8272
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8035
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
8258
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
6688
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
5847
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
5431
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
3886
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...
0
3927
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.