Baffling .NET Threading issue.

  • Thread starter Thread starter paul.driegen
  • Start date Start date
P

paul.driegen

Hi all,


Hopefully some gurus here can offer some insight into possible causes
of this problem..or at least point me in the right direction as to how
to solve it.


Consider:


_transmitThread = new Thread(new ThreadStart(TransmitLoop));
_transmitThread.Priority = ThreadPriority.Normal;
_transmitThread.Name = "Client Transmitter Loop";
_transmitThread.Start();


All seems well..right? the thing is..the TransmitLoop() function is
never executed.. it's never even started. If I check the IsAlive
property of _transmitThread later on in the program execution in the
app's main thread, the value is false.


No exception is raised, the assembly runs fine..except the worker
function is never called.


Even more troubling is that this code snippet belongs to a client
application that is deployed on ~15 servers in a network. The problem
outlined above only occurs on 2 of the servers. The remaining machines
execute the assembly correctly, the TransmitLoop() thread is running
just fine.


Has anyone ever anything something like this? Any ideas on how to find
the cause of the problem? Like I mentioned, I can't debug it because it
works fine in a debug environment, as well as most of the production
enviroments.

I suspect that some exception must be thrown deep in the framework
somewhere that is raised on a thread that isn't hooked to my code..but
I don't know how to catch it..if I can at all?


Any help / insight you could provide would be much appreciated.


Thanks,
Paul.
 
In main, set up a handler for Application.ThreadException. That will catch
an unhandled exception in the new thread, and that sounds like what the
problem is assuming all is well with uses of _transmitThread in your main
thread.
 
Don't know if this helps since I'm somewhat new to threading but
you might want to try to put:

Thread.Sleep(0)

after the Start statement. I read somewhere that the thread can't
start until the current thread yields, either by a Sleep or an
End Sub. Most of the examples I've seen just happen to do the
Start as the last instruction in a subroutine, but if you have a long
unyielding process after the Start statement your new thread may
appear not to start.
 
Back
Top