Question Create Idle worker thread

Darknesss

New member
Joined
Sep 25, 2008
Messages
1
Programming Experience
10+
I have a rather specific problem that I could not solve so far. :mad:

Problem description:
I have a classlibrary that contains a function that is executed by a scheduler mechanism.
This function needs to call certain library functions (3rd party) but they need to be executed in a STA thread (single threaded apartmentstate) to avoid issues with that 3rd party library (not Threadsafe).

In our current solution, we have a class and pass all parameters to the class. Next, we create a new STA thread with a function from that class to keep all objects in the correct environment and wait for the thread to finish.

The problem is that this causes a buildup of connections in another component because it's always a new thread that creates a connection. These connections have a timeout but it still leads to unwanted effects.

What I am looking for is a way to have classlibrary start a STA background thread that sits there waiting idle (preferably not with thread.sleep)
Then, when the function from the classlibrary gets called, it will pass a command to the thread, wait for the answer and continue BUT the background thread should stay alive, idle waiting for new commands.

A little bit like a windows form waiting for button clicks, but without the window...


It would be great if some of you could point me to a possible solution or idea on how to implement this for .net 1.1.
Current code is in VB.net but C# solutions are also good.

I hope there are some great minds wandering these forums!
 
Back
Top