467,858 Members | 1,607 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,858 developers. It's quick & easy.

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 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 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.
Kris.
Nov 17 '05 #1
  • viewed: 8224
Share:
4 Replies

Does your application "hang" when you run it as an application?

Whenever I write a windows service application, there is a core section
which exposes start and stop methods which exist in an assembly (DLL). From
here I can apply any front end I like, whether it be windows service,
windows dialog, or a console application.
While doing any sort of debugging information, I flood the area I'm not sure
about with Console.Writeline(...) calls so that the program flow can be
easily traced, with details of relevant variables. In this case it would be
worth checking the status of your references to your COM objects. Are you
listening to a serial port or sending data to it?

From here it seems unlikely it's the "windows service" part of the
application that's causing the freeze.

"Kris" <Kr**@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
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 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.
Kris.

Nov 17 '05 #2
Dan,
Thanks for your reply. To answer your questions I both listen and talk to
the serial port and I actually have a GUI app that uses the same code as my
Service. I never ran it long enough to make it crash though. My crash
(freeze) occurs very infrequently (recently it was 6 weeks) and only on one
particular computer. Actually in the past it was freezing every few hours
also. Maybe I should have changed the emphasis of my question to how to kill
the frozen service rather than why it freezes. If I can kill it then it will
be restarted automatically by another service. Right now I can't kill it by
using Process.Kill() nor manually from the command line nor through the Task
Manager nor can I stop it from the Services. The only way to stop it is to
reboot the computer. Apparently it is messed up big time. No exceptions are
ever being caught. Thanks again.
Kris.

"Dan Bass" wrote:

Does your application "hang" when you run it as an application?

Whenever I write a windows service application, there is a core section
which exposes start and stop methods which exist in an assembly (DLL). From
here I can apply any front end I like, whether it be windows service,
windows dialog, or a console application.
While doing any sort of debugging information, I flood the area I'm not sure
about with Console.Writeline(...) calls so that the program flow can be
easily traced, with details of relevant variables. In this case it would be
worth checking the status of your references to your COM objects. Are you
listening to a serial port or sending data to it?

From here it seems unlikely it's the "windows service" part of the
application that's causing the freeze.

"Kris" <Kr**@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
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 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.
Kris.


Nov 17 '05 #3

if it's on a windows 2000+ machine there's a handy utility called "kill". If
you go to the command prompt and type "kill /f <processName>" it should nuke
it.

Better to find a fix to a problem than a work around though.
Check the Nt Event log at the time of the freeze, for example.
Was there other activity going on at the same time on the machine (i.e. low
on resources).
Are the ports your using being released properly?
.... and so the list of questions can go on.
"Kris" <Kr**@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
Dan,
Thanks for your reply. To answer your questions I both listen and talk to
the serial port and I actually have a GUI app that uses the same code as
my
Service. I never ran it long enough to make it crash though. My crash
(freeze) occurs very infrequently (recently it was 6 weeks) and only on
one
particular computer. Actually in the past it was freezing every few hours
also. Maybe I should have changed the emphasis of my question to how to
kill
the frozen service rather than why it freezes. If I can kill it then it
will
be restarted automatically by another service. Right now I can't kill it
by
using Process.Kill() nor manually from the command line nor through the
Task
Manager nor can I stop it from the Services. The only way to stop it is to
reboot the computer. Apparently it is messed up big time. No exceptions
are
ever being caught. Thanks again.
Kris.

"Dan Bass" wrote:

Does your application "hang" when you run it as an application?

Whenever I write a windows service application, there is a core section
which exposes start and stop methods which exist in an assembly (DLL).
From
here I can apply any front end I like, whether it be windows service,
windows dialog, or a console application.
While doing any sort of debugging information, I flood the area I'm not
sure
about with Console.Writeline(...) calls so that the program flow can be
easily traced, with details of relevant variables. In this case it would
be
worth checking the status of your references to your COM objects. Are you
listening to a serial port or sending data to it?

From here it seems unlikely it's the "windows service" part of the
application that's causing the freeze.

"Kris" <Kr**@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
>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
> 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.
> Kris.


Nov 17 '05 #4
Dan,
Thanks again. In the past I was trying to terminate it by using kill
<processId> from the command line which did not work. Whenever I have a next
chance I will try to use kill /f which will still not fix my problem because
as I mentioned I'm trying to kill it programmatically with no effect and I
don't understand why. Seems like OS somehow lost track of this service. No
messages were reported in the event logs for the time when it crashed. As you
said there are just too many things that can go wrong - serial port, old COM
dlls, remoting. But it work "most" of the time and on all other machines it
works all the time.
Regards, Kris.
"Dan Bass" wrote:

if it's on a windows 2000+ machine there's a handy utility called "kill". If
you go to the command prompt and type "kill /f <processName>" it should nuke
it.

Better to find a fix to a problem than a work around though.
Check the Nt Event log at the time of the freeze, for example.
Was there other activity going on at the same time on the machine (i.e. low
on resources).
Are the ports your using being released properly?
.... and so the list of questions can go on.
"Kris" <Kr**@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
Dan,
Thanks for your reply. To answer your questions I both listen and talk to
the serial port and I actually have a GUI app that uses the same code as
my
Service. I never ran it long enough to make it crash though. My crash
(freeze) occurs very infrequently (recently it was 6 weeks) and only on
one
particular computer. Actually in the past it was freezing every few hours
also. Maybe I should have changed the emphasis of my question to how to
kill
the frozen service rather than why it freezes. If I can kill it then it
will
be restarted automatically by another service. Right now I can't kill it
by
using Process.Kill() nor manually from the command line nor through the
Task
Manager nor can I stop it from the Services. The only way to stop it is to
reboot the computer. Apparently it is messed up big time. No exceptions
are
ever being caught. Thanks again.
Kris.

"Dan Bass" wrote:

Does your application "hang" when you run it as an application?

Whenever I write a windows service application, there is a core section
which exposes start and stop methods which exist in an assembly (DLL).
From
here I can apply any front end I like, whether it be windows service,
windows dialog, or a console application.
While doing any sort of debugging information, I flood the area I'm not
sure
about with Console.Writeline(...) calls so that the program flow can be
easily traced, with details of relevant variables. In this case it would
be
worth checking the status of your references to your COM objects. Are you
listening to a serial port or sending data to it?

From here it seems unlikely it's the "windows service" part of the
application that's causing the freeze.

"Kris" <Kr**@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
>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
> 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.
> Kris.


Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jacob Crossley | last post: by
7 posts views Thread by Ashish Khandelwal | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.