Connecting Tech Pros Worldwide Forums | Help | Site Map

Monitoring Thread Activity

Jerry Spence1
Guest
 
Posts: n/a
#1: Nov 21 '08
I have a thread which is misbehaving. It's due to a call to
my.computer.network.ping sometimes never responding (I'm assuming this is a
bug in .Net 2.0). I need to have a thread running which constantly monitors
all the other threads in my program (actually implemented using background
workers) and if it stops using CPU, then kill it, and relaunch it.

How can I implement the monitoring part?

-Jerry



=?Utf-8?B?QU1lcmNlcg==?=
Guest
 
Posts: n/a
#2: Nov 21 '08

re: Monitoring Thread Activity


I have a thread which is misbehaving. It's due to a call to
Quote:
my.computer.network.ping sometimes never responding
In what way misbehaving? Ping can raise an exception. Are you handling
exceptions? Ping with a long timeout can wait for a long time before
returning. Do you use the timeout parameter?
Quote:
(I'm assuming this is a
bug in .Net 2.0).
I would be surprised if there is a .net bug in this area.
Quote:
I need to have a thread running which constantly monitors
all the other threads in my program (actually implemented using background
workers) and if it stops using CPU, then kill it, and relaunch it.
I suggest you investigate why your thread is misbehaving and that you not
implement a thread that watches other threads. But if you must, I would
suggest that each monitored thread periodically append some data to a
thread-safe queue. The data could be anything you want, eg a heartbeat
notification, or some statistics about the thread's throughput, or even some
problem that is the worker thread has encountered. A new thread (or your
main thread) could read this queue from time to time looking for trouble.
But, I urge you to not proceed down this path.

Jerry Spence1
Guest
 
Posts: n/a
#3: Nov 21 '08

re: Monitoring Thread Activity



"AMercer" <AMercer@discussions.microsoft.comwrote in message
news:5BC44675-C8CA-47E8-B756-926CE4AE24B0@microsoft.com...
Quote:
Quote:
>I have a thread which is misbehaving. It's due to a call to
>my.computer.network.ping sometimes never responding
>
In what way misbehaving? Ping can raise an exception. Are you handling
exceptions? Ping with a long timeout can wait for a long time before
returning. Do you use the timeout parameter?
>
Quote:
>(I'm assuming this is a
>bug in .Net 2.0).
>
I would be surprised if there is a .net bug in this area.
>
Quote:
>I need to have a thread running which constantly monitors
>all the other threads in my program (actually implemented using
>background
>workers) and if it stops using CPU, then kill it, and relaunch it.
>
I suggest you investigate why your thread is misbehaving and that you not
implement a thread that watches other threads. But if you must, I would
suggest that each monitored thread periodically append some data to a
thread-safe queue. The data could be anything you want, eg a heartbeat
notification, or some statistics about the thread's throughput, or even
some
problem that is the worker thread has encountered. A new thread (or your
main thread) could read this queue from time to time looking for trouble.
But, I urge you to not proceed down this path.
Thanks for your reply. Sometimes the ping statement crashes with a protected
memory exception (I can catch this) and sometimes it never returns (I have a
timeout of 1000ms) which I can't catch. I have tried investigating this
error for ages (it happens on all our production PCs) and felt that some
sort of monitor would be best to crash the thread until I can upgrade to
..Net 3.5.

Yes I thought of a watchdog system but how do I get a handle on the actual
thread (process ID perhaps) and how do I stop it with another process?

-Jerry


Closed Thread