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

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.Timer
which
detects that the main thread stopped working. I was trying to stop it
by
using System.ServiceProcess.ServiceController.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 3184
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.comwrote in message
news:9f**********************************@e10g2000 prf.googlegroups.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.Timer
which
detects that the main thread stopped working. I was trying to stop it
by
using System.ServiceProcess.ServiceController.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
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...
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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$) { } ...
0
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...
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...
0
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...

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.