C# Communication between threads.

Posted by GT on Stack Overflow See other posts from Stack Overflow or by GT
Published on 2010-04-13T01:08:50Z Indexed on 2010/04/13 1:12 UTC
Read the original article Hit count: 530

Filed under:
|

Hi,

I am using .NET 3.5 and am trying to wrap my head around a problem (not being a supreme threading expert bear with me).

I have a windows service which has a very intensive process that is always running, I have put this process onto a separate thread so that the main thread of my service can handle operational tasks - i.e., service audit cycles, handling configuration changes, etc, etc.

I'm starting the thread via the typical ThreadStart to a method which kicks the process off - call it workerthread.

On this workerthread I am sending data to another server, as is expected the server reboots every now and again and connection is lost and I need to re-establish the connection (I am notified by the lost of connection via an event). From here I do my reconnect logic and I am back in and running, however what I easily started to notice to happen was that I was creating this worker thread over and over again each time (not what I want).

Now I could kill the workerthread when I lose the connection and start a new one but this seems like a waste of resources.

What I really want to do, is marshal the call (i.e., my thread start method) back to the thread that is still in memory although not doing anything.

Please post any examples or docs you have that would be of use.

Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about threading