[quoted text, click to view] celoftis wrote:
> I suppose I need to get more famaliar with thread debugging info. In
> my output window, I messages telling me that "thread 0x#### has exited
> with return code 0x0" - which looks good to me (no error number)... my
> question is how I relate the 0x#### number back to the threads that I
> create - none of the thread attributes/properties produce this number
> when I investigate them on a known thread. Where does this number come
> from?
Which number? The "0x####" number? Or the actual return code? I'm
assuming the former, for the moment.
To be honest, I've never looked closely that the thread ID output in the
console. .NET is always on its own making threads that start up and
exit, causing that message to be more of a distraction than a help to
me. If I care about the return code from a thread, I've got code
somewhere else that checks it.
That said, I'll bet that the ID is either the managed thread ID
(Thread.ManagedThreadId) or the unmanaged thread ID (Windows function
GetThreadId()). Frankly, I'm still a little confused about the
relationship between managed threads and unmanaged threads. One day
I'll read that they are one and the same, though not guaranteed to be
so, the next day I'll read that .NET already doesn't map a managed
thread to a specific unmanaged thread.
Who knows. But it wouldn't be hard to write a little test app to just
Debug.WriteLine() the two thread IDs (managed and unmanaged) just before
a thread exits, and see which if either matches the ID in the "thread
exited" message (you might return some non-zero number from the thread,
just in case some other thread exits at the same time, to make it easier
to match up the thread exit message with your own test thread).
[quoted text, click to view] > Yes, I have read that the debugger throws false context deadlock
> errors when debugging - I was thinking that I wasn't falling under
> that bogus case b/c I get the error when the app is running vs. being
> stopped in the debugger. Maybe just running the app in Debug mode
> triggers the error? Not a real secure feeling that I am left with on
> this...
I have the same problem with the LoaderLock MDA exception. All signs
suggest I should be able to ignore it in the situations in which I run
into it, but it still bothers me that it shows up.
Anyway, if I'm recalling correctly, your deadlock error is similar, and
is an MDA exception. So it will only ever show up when you are running
with the debugger, and it will _always_ show up if the conditions it
describes are met, whether or not those conditions are really a problem.
At the heart of the error is the assumption by the debugger that if a
thread with a message queue does not call a function to retrieve a
message from the queue after a certain amount of time, then that thread
may be deadlocked. But there are other reasons a thread may not get to
retrieve a message within a specific amount of time. One of those
reasons is that you are stepping slowly through the debugger,
interfering with a thread's ability to execute its message pump.
Another is that the thread has a message pump, but also has some code
that takes a long time to complete in response to processing some message.
Now, I think it could be argued that in that latter case, it may
actually be a design flaw to have code like that. I feel that threads
with message queues are generally threads that should not have lengthy
tasks executed in them. Those threads should instead delegate those
tasks to some other thread without a message queue. But that doesn't
mean that it's a fundamental programming error to fail to do that. It
just means that's not how _I_ would do it. There's no shortage of
people out there who will argue that's not a useful metric at all. :)
IMHO more important is the question of whether there is actually a
deadlock condition when you see the error. And one hopes that you would
easily detect a deadlock condition, at least from a user's point of
view. That is, if deadlock occurs, your application should essentially
just stop working, at least partially. It can be tricky to detect
deadlock from within the code, but from where the user's sitting it's
usually pretty obvious. The program just stops doing anything. :)
So, assuming your program continues to do the work it's supposed to be
doing, even when you get this error, I'd say it's at worst suggesting
there may be room for improvement in your design. At the very least, in
that situation I don't think it's something that you _have_ to fix (even
if it's something I might personally look more closely at).