VB.Net - Multi-Threaded Model Having Problems..

B

BergRD

Salutations!

New to the forums but have gotten many an idea from lurking over the
past few months but alas it's time to begin positing; posting to a
problem I cannot seem to resolve. This is a long description but my
hopes are the more information the better someone may be able to help
:)

The Problem:
----------------------------------------------------------------------
I have an application that, based on configuration, spins a new
class object into a thread. These threads enable communications to
specific hardware running on a manufacturing floor.

Each object, in and of itself, establishes communications to said
hardware and begins actively monitoring for events, data and
changes.

Upon starting the object, inside a new thread spawned by the parent
thread, I begin my communications and once done perform a .WaitAll()
call on the `Thread.CurrentThread`. This leaves the thread in a
waitstate allowing the the thread and the object contained within
persistance as it waits for it's work to be triggered.

Todate, I have been able to successfully spin these objects and
persist the threads while waiting and event triggers raised within
the threaded objects work fine however add another twist; MSMQ.

Once the parent service, main thread, spins an instance of an
object class in a new thread occationally the parent receives
messages via MSMQ wherein the parent needs to instruct the child
objects (on threads) to perform a task. Calls into these
objects/threads are proving harder than I had initially anticipated
and since I cannot seem to get the call to invoke on the target
threaded objects context I become deadlocked in my communications
process.

Quite simply the application logic is:

Startup:
--------------
Service starts, creates new Parent Object
Parent Object creates new Child Object and adds to internal
collection
Parent Object creates new thread for each Child Object and issues
.Start
Child Object spins up in own thread establishing communications
Child Object, utilizing CallBack, notifies Parent of Success and
.WaitOne
Parent Object repeats process until all Child Objects created

Runtime:
--------------
Child Object manages it's own thread, processes and methods
Parent Object receives MSMQ Message for Child Object
Parent Object calls method inside Child Object to perform task


The Attempts:
----------------------------------------------------------------------
I have tried various methods to wake the Child thread and issue the
work via events, callbacks and asynch invokes without success. The
Child Object is on a STA Thread and upon the Parent Object getting
the MSMQ Event for a message arrival and the subsequent call to the
Child, it seems .NET is spinning off a *new* MTA thread with the call
to the Child Object's method thus deadlocking my communications since
the Child is already using the same resources.

I'm tried to implement the ISerializableInvoke, ContextBoundObject
and other `Serializing` avenues in .NET but each and everytime I
cannot seem to communicate to the Child thread to wake it and perform
the task given.


Whew, said this would be long eh? :D

If anyone could shed light in how to gain the context of the
threaded Child Object to issues method calls on the thread the Child
Object resides would be must helpful!

Additional information can be provided but since encapsulates the
`general idea` of the problem I'll finish up.

Thanks in advance

Richard Berg
 
D

David Browne

BergRD said:
Salutations!

New to the forums but have gotten many an idea from lurking over the
past few months but alas it's time to begin positing; posting to a
problem I cannot seem to resolve. This is a long description but my
hopes are the more information the better someone may be able to help
:)

The Problem:
----------------------------------------------------------------------
I have an application that, based on configuration, spins a new
class object into a thread. These threads enable communications to
specific hardware running on a manufacturing floor.

Each object, in and of itself, establishes communications to said
hardware and begins actively monitoring for events, data and
changes.

Upon starting the object, inside a new thread spawned by the parent
thread, I begin my communications and once done perform a .WaitAll()
call on the `Thread.CurrentThread`. This leaves the thread in a
waitstate allowing the the thread and the object contained within
persistance as it waits for it's work to be triggered.

Todate, I have been able to successfully spin these objects and
persist the threads while waiting and event triggers raised within
the threaded objects work fine however add another twist; MSMQ.

Once the parent service, main thread, spins an instance of an
object class in a new thread occationally the parent receives
messages via MSMQ wherein the parent needs to instruct the child
objects (on threads) to perform a task. Calls into these
objects/threads are proving harder than I had initially anticipated
and since I cannot seem to get the call to invoke on the target
threaded objects context I become deadlocked in my communications
process.

Here's a class I wrote that might help.

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&[email protected]

You would create a new SingleThreadWorkQueue using a delegate pointing to
the business end of your child object. Then from the main thread just use
the SingleThreadWorkQueue.AddWork method. It will wake up the worker thread
(if it is idle) and queue the work if not.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top