Thread just stops running

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have noticed how the thread I created just stops running. I have added
several exceptions to the thread

System.Threading.SynchronizationLockException
System.Threading.ThreadAbortException
System.Threading.ThreadInterruptedException
System.Threading.ThreadStateException

to see if I could get more information about why the thread stops running
but that code is never executed. Any ideas on how I can debug this?

Thanks in advance.
 
You need to provide more context than this if you want the problem to be
solved

--
Regards,
Alvin Bruney

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
 
A thread stops running as soon as its parent thread stops running.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
Thanks Kevin. The parent thread (as I understand it) is the aspnet_wp process
and as far I can tell, it is still running. The reason why I am saying this
is because I can access other ASP.NET applications on the same server. I have
also checked the event log and I don't aspnet_wp being recycled. What am I
missing?
 
what is the looping structure in your thread? are you sure you are catching
all errors? what is its normal exit trigger?

if you code it correctly a thread will run the life of the appdomain its
created in.

-- bruce (sqlwork.com)





| Thanks Kevin. The parent thread (as I understand it) is the aspnet_wp
process
| and as far I can tell, it is still running. The reason why I am saying
this
| is because I can access other ASP.NET applications on the same server. I
have
| also checked the event log and I don't aspnet_wp being recycled. What am I
| missing?
|
| "Kevin Spencer" wrote:
|
| > A thread stops running as soon as its parent thread stops running.
| >
| > --
| > HTH,
| >
| > Kevin Spencer
| > Microsoft MVP
| > ..Net Developer
| > What You Seek Is What You Get.
| >
| > | > >I have noticed how the thread I created just stops running. I have
added
| > > several exceptions to the thread
| > >
| > > System.Threading.SynchronizationLockException
| > > System.Threading.ThreadAbortException
| > > System.Threading.ThreadInterruptedException
| > > System.Threading.ThreadStateException
| > >
| > > to see if I could get more information about why the thread stops
running
| > > but that code is never executed. Any ideas on how I can debug this?
| > >
| > > Thanks in advance.
| > >
| >
| >
| >
 
Hello Bruce. I am sure I am catching all errors:

System.Threading.SynchronizationLockException
System.Threading.ThreadAbortException
System.Threading.ThreadInterruptedException
System.Threading.ThreadStateException
System.Exception

The looping structure is a

While True
.... (local code)
.... Call another method
.... (+ local code)
End While

I have not added an exit trigger yet. I wanted to fix this problem first.
 
then try

while true
try
... your thread code
catch
try
log error
catch
.. can't log
end try
end try
end while

note: your thread will be running with the asp.net worker process id, and
will have limited permissions.

-- bruce (sqlwork.com)

| Hello Bruce. I am sure I am catching all errors:
|
| System.Threading.SynchronizationLockException
| System.Threading.ThreadAbortException
| System.Threading.ThreadInterruptedException
| System.Threading.ThreadStateException
| System.Exception
|
| The looping structure is a
|
| While True
| ... (local code)
| ... Call another method
| ... (+ local code)
| End While
|
| I have not added an exit trigger yet. I wanted to fix this problem first.
|
|
| "bruce barker" wrote:
|
| > what is the looping structure in your thread? are you sure you are
catching
| > all errors? what is its normal exit trigger?
| >
| > if you code it correctly a thread will run the life of the appdomain
its
| > created in.
| >
| > -- bruce (sqlwork.com)
| >
| >
| >
| >
| >
| > | > | Thanks Kevin. The parent thread (as I understand it) is the aspnet_wp
| > process
| > | and as far I can tell, it is still running. The reason why I am saying
| > this
| > | is because I can access other ASP.NET applications on the same server.
I
| > have
| > | also checked the event log and I don't aspnet_wp being recycled. What
am I
| > | missing?
| > |
| > | "Kevin Spencer" wrote:
| > |
| > | > A thread stops running as soon as its parent thread stops running.
| > | >
| > | > --
| > | > HTH,
| > | >
| > | > Kevin Spencer
| > | > Microsoft MVP
| > | > ..Net Developer
| > | > What You Seek Is What You Get.
| > | >
| > | > | > | > >I have noticed how the thread I created just stops running. I have
| > added
| > | > > several exceptions to the thread
| > | > >
| > | > > System.Threading.SynchronizationLockException
| > | > > System.Threading.ThreadAbortException
| > | > > System.Threading.ThreadInterruptedException
| > | > > System.Threading.ThreadStateException
| > | > >
| > | > > to see if I could get more information about why the thread stops
| > running
| > | > > but that code is never executed. Any ideas on how I can debug
this?
| > | > >
| > | > > Thanks in advance.
| > | > >
| > | >
| > | >
| > | >
| >
| >
| >
 
Hello Bruce and thank you for your suggestion. I did what you told me and
unfortunately nothing changed. I can still see one thread (I only created
two) dying. Look at the log I am outputting:

The entry at the bottom represents me stopping the aspnet_wp.exe process.
Then you will thread 1 and 2. Around 8:37:04 is when thread 0 died...

DATE,TIME,EVENT CONTENT

3/9/2005,8:38:49 AM,Thread ID# 1;
3/9/2005,8:38:46 AM,Thread ID# 1;
3/9/2005,8:38:42 AM,Thread ID# 1;
3/9/2005,8:38:39 AM,Thread ID# 1;
3/9/2005,8:38:36 AM,Thread ID# 1;
3/9/2005,8:38:33 AM,Thread ID# 1;
3/9/2005,8:38:30 AM,Thread ID# 1;
3/9/2005,8:38:27 AM,Thread ID# 1;
3/9/2005,8:38:24 AM,Thread ID# 1;
3/9/2005,8:38:20 AM,Thread ID# 1;
3/9/2005,8:38:17 AM,Thread ID# 1;
3/9/2005,8:38:14 AM,Thread ID# 1;
3/9/2005,8:38:11 AM,Thread ID# 1;
3/9/2005,8:38:08 AM,Thread ID# 1;
3/9/2005,8:38:05 AM,Thread ID# 1;
3/9/2005,8:38:02 AM,Thread ID# 1;
3/9/2005,8:37:58 AM,Thread ID# 1;
3/9/2005,8:37:55 AM,Thread ID# 1;
3/9/2005,8:37:52 AM,Thread ID# 1;
3/9/2005,8:37:49 AM,Thread ID# 1;
3/9/2005,8:37:46 AM,Thread ID# 1;
3/9/2005,8:37:42 AM,Thread ID# 1;
3/9/2005,8:37:39 AM,Thread ID# 1;
3/9/2005,8:37:36 AM,Thread ID# 1;
3/9/2005,8:37:33 AM,Thread ID# 1;
3/9/2005,8:37:30 AM,Thread ID# 1;
3/9/2005,8:37:27 AM,Thread ID# 1;
3/9/2005,8:37:24 AM,Thread ID# 1;
3/9/2005,8:37:21 AM,Thread ID# 1;
3/9/2005,8:37:17 AM,Thread ID# 1;
3/9/2005,8:37:14 AM,Thread ID# 1;
3/9/2005,8:37:11 AM,Thread ID# 1;
3/9/2005,8:37:08 AM,Thread ID# 1;
3/9/2005,8:37:04 AM,Thread ID# 1;
3/9/2005,8:37:04 AM,Thread ID# 0;
3/9/2005,8:37:01 AM,Thread ID# 1;
3/9/2005,8:37:01 AM,Thread ID# 0;
3/9/2005,8:36:58 AM,Thread ID# 1;
3/9/2005,8:36:58 AM,Thread ID# 0;
3/9/2005,8:36:55 AM,Thread ID# 1;
3/9/2005,8:36:54 AM,Thread ID# 0;
3/9/2005,8:36:52 AM,Thread ID# 1;
3/9/2005,8:36:51 AM,Thread ID# 0;
3/9/2005,8:36:49 AM,Thread ID# 1;
3/9/2005,8:36:48 AM,Thread ID# 0;
3/9/2005,8:36:45 AM,Thread ID# 1;
3/9/2005,8:36:45 AM,Thread ID# 0;
3/9/2005,8:36:42 AM,Thread ID# 0;
3/9/2005,8:36:42 AM,Thread ID# 1;
3/9/2005,8:36:39 AM,Thread ID# 0;
3/9/2005,8:36:39 AM,Thread ID# 1;
3/9/2005,8:36:36 AM,Thread ID# 1;
3/9/2005,8:36:33 AM,Thread ID# 1;
3/9/2005,8:36:30 AM,Thread ID# 1;
3/9/2005,8:36:27 AM,Thread ID# 1;
3/9/2005,8:36:26 AM,Thread ID# 0;
3/9/2005,8:36:23 AM,Thread ID# 1;
3/9/2005,8:36:22 AM,Thread ID# 0;
3/9/2005,8:36:20 AM,Thread ID# 1;
3/9/2005,8:36:18 AM,Thread ID# 0;
3/9/2005,8:36:17 AM,Thread ID# 1;
3/9/2005,8:36:14 AM,Thread ID# 0;
3/9/2005,8:36:14 AM,Thread ID# 1;
3/9/2005,8:36:10 AM,Thread ID# 1;
3/9/2005,8:36:10 AM,Thread ID# 0;
3/9/2005,8:36:07 AM,Thread ID# 1;
3/9/2005,8:36:06 AM,Thread ID# 0;
3/9/2005,8:36:04 AM,Thread ID# 1;
3/9/2005,8:36:02 AM,Thread ID# 0;
3/9/2005,8:36:01 AM,Thread ID# 1;
3/9/2005,8:35:58 AM,Thread ID# 0;
3/9/2005,8:35:57 AM,Thread ID# 1;
3/9/2005,8:35:54 AM,Thread ID# 1;
3/9/2005,8:35:54 AM,Thread ID# 0;
3/9/2005,8:35:51 AM,Thread ID# 1;
3/9/2005,8:35:50 AM,Thread ID# 0;
3/9/2005,8:35:48 AM,Thread ID# 1;
3/9/2005,8:35:46 AM,Thread ID# 0;
3/9/2005,8:35:45 AM,Thread ID# 1;
3/9/2005,8:35:43 AM,Thread ID# 0;
3/9/2005,8:35:42 AM,Thread ID# 1;
3/9/2005,8:35:40 AM,Thread ID# 0;
3/9/2005,8:35:38 AM,Thread ID# 1;
3/9/2005,8:35:37 AM,Thread ID# 0;
3/9/2005,8:35:35 AM,Thread ID# 1;
3/9/2005,8:35:34 AM,Thread ID# 0;
3/9/2005,8:35:32 AM,Thread ID# 1;
3/9/2005,8:35:31 AM,Thread ID# 0;
3/9/2005,8:35:29 AM,Thread ID# 1;
3/9/2005,8:35:28 AM,Thread ID# 0;
3/9/2005,8:35:26 AM,Thread ID# 1;
3/9/2005,8:35:25 AM,Thread ID# 0;
3/9/2005,8:35:23 AM,Thread ID# 1;
3/9/2005,8:35:21 AM,Thread ID# 0;
3/9/2005,8:35:20 AM,Thread ID# 1;
3/9/2005,8:35:18 AM,Thread ID# 0;
3/9/2005,8:35:16 AM,Thread ID# 1;
3/9/2005,8:35:15 AM,Thread ID# 0;
3/9/2005,8:35:13 AM,Thread ID# 1;
3/9/2005,8:35:12 AM,Thread ID# 0;
3/9/2005,8:35:10 AM,Thread ID# 1;
3/9/2005,8:35:09 AM,Thread ID# 0;
3/9/2005,8:35:07 AM,Thread ID# 1;
3/9/2005,8:35:06 AM,Thread ID# 0;
3/9/2005,8:35:03 AM,Thread ID# 1;
3/9/2005,8:35:03 AM,Thread ID# 0;
3/9/2005,8:35:00 AM,Thread ID# 1;
3/9/2005,8:35:00 AM,Thread ID# 0;
3/9/2005,8:34:57 AM,Thread ID# 1;
3/9/2005,8:34:57 AM,Thread ID# 0;
3/9/2005,8:34:54 AM,Thread ID# 1;
3/9/2005,8:34:54 AM,Thread ID# 0;
3/9/2005,8:34:51 AM,Thread ID# 1;
3/9/2005,8:34:51 AM,Thread ID# 0;
3/9/2005,8:34:48 AM,Thread ID# 1;
3/9/2005,8:34:48 AM,Thread ID# 0;
3/9/2005,8:34:45 AM,Thread ID# 1;
3/9/2005,8:34:45 AM,Thread ID# 0;
3/9/2005,8:34:42 AM,Thread ID# 1;
3/9/2005,8:34:41 AM,Thread ID# 0;
3/9/2005,8:34:38 AM,Thread ID# 1;
3/9/2005,8:34:38 AM,Thread ID# 0;
3/9/2005,8:34:23 AM,ASP.NET 1.1.4322.0,Error,1000,N/A,aspnet_wp.exe (PID:
3796) stopped unexpectedly.
 
I found the problem. It was in the method being called by the thread. After
adding tons of logging and bunch of catches I found it. Here are the details:

One of my test cases was to simulate a server crash. During the crashing, if
there was any communication that was already started by the client, it could
not be finished. So the “waiting for data†routine went into an infinite loop.

I also learned that the following command:

sender.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket,
System.Net.Sockets.SocketOptionName.ReceiveTimeout, 10000)

does nothing if the server crashed right after the communication
(client/server) started. So I added a timer in the “waiting for dataâ€
routine. When the time expires I exit the loop throwing an exception, which
gives control back to the thread.

Thank you Bruce, Kevin and Alvin.
 
Back
Top