How to re-enter a thread?

  • Thread starter Thread starter Mountain Bikn' Guy
  • Start date Start date
M

Mountain Bikn' Guy

I'm using async delegate calls. I would like to re-enter my initial thread
after the callback. (I'm not using UI controls, so Control.Invoke is not the
solution.) How can I manually implement behavior like Control.Invoke? How
can I re-enter my initial thread? Any suggestions?
Thanks!
Mountain

I already searched Google Groups and found something on this topic, but no
solution:
http://groups.google.com/groups?hl=...ff&selm=#[email protected]

Here's the most relevant prior post I found (again, no solution):


From: Lior Amar ([email protected])
Subject: Re: Threads and Delegates
View: Complete Thread (18 articles)
Original Format
Newsgroups: microsoft.public.dotnet.languages.vb
Date: 2003-09-29 16:24:04 PST


Hey Peter,

Thanks for the links but these explain more on shared resources. Not really
having issues with multi-threading as is. More interested on making my
thread reentrant. Tried even overriding marshalling but nothing doing. Super
simple to thread in .NET but man is it tough to re-enter a thread. I know it
can be done with a Form/Component with the BeginInvoke. Tried that with
delegates but it doesn't do it. Did learn that if you try enough Async
delegate invokation that sooner or later the delegate call will be made on a
different thread also. Also found that you can make recursive
delegates....not recommended though

Whatever approach I take, I can not get the call to reenter my initial
thread. I'm doing this with C++ and an ATL component but I would rather a
complete VB.NET solution.

Things I've tried so far:

1. Delegates
2. Shared Resources
3. Inheriting the RealProxy and Implementing the IRemotingTypeInfo to try
and create a Single Threaded object using MarshalByRefObject.
4. ContextBoundObject
5. Sacrificing a small animal

Best results so far have been with #5

I've pretty much just gone with my C++ workaround but plan on working on it
more on my free time. It just seems like something that shouldn't be that
difficult!

Any ideas on what else I should try...Would love to know what the
Form/Component.BeginInvoke does to reenter it's thread

Thanks,

Lior
 
Hi,

You can't.
Why would you even need to?
You'll have to syncronize your actions somehow (there are plenty of
synchronization mechanisms).
BTW, what kind of mounting bike do you have?
 
Mountain Bikn' Guy said:
I'm using async delegate calls. I would like to re-enter my initial thread
after the callback. (I'm not using UI controls, so Control.Invoke is not the
solution.) How can I manually implement behavior like Control.Invoke? How
can I re-enter my initial thread? Any suggestions?
Thanks!
Mountain

First off your main thread will have to be waiting. The delegate callback
will happen on a background thread. From the callback function you must
signal your main thread somehow, and probably pass it some data.

For instance you could use a Queue. Have your main thread lock the queue,
see if there is anyting on the queue (the callback may already be done!),
and then wait on its monitor. When the callback happens the delegate
function locks the queue, enqueues the state object and pulses the queue's
monitor, releasing the main thread. The main thread then deQueues the state
object and processes it.

I bet there's a slicker way to do it somehow, but using basic thread
syncronization mechanisms is good practice.

David
 
Not sure if this is what your looking for (You could be looking for
something else). but:

I am using events to communicate between threads. I have a communications
class that is polling on a back ground thread. In the Commucations class I
declaire something like:

Public Event Update_Status(ByVal Message_String As String)


In the Main module, i declaire something like:

AddHandler ClientComm.Update_Status, AddressOf Update_Status

Is this what your looking for? In the Comm module I just invoke the
Update_Status method to communicate to the main module that something
happened.

g.
 
If I could read VB better, I might know if this was something like what I am
looking for ;)

Is this any different from normal C# events, because the normal use of
events doesn't do it.
 
Hi David,
Thanks for your reply, but that's not what I was looking for (unless I am
missing your point). I was hoping the C# group would know something the VB
group didn't. The conversation at this link pretty much sums up what I'm
looking for:
http://groups.google.com/groups?hl=...elm=%237GECCuhDHA.1180%40TK2MSFTNGP12.phx.gbl

The guy who made the original post didn't find a satisfactory VB.NET
solution and it seems like C# won't be any better.
Regards,
Mountain
 
Hi,

Of course I do :)
I used to have Cannondale M700 10 years ago - when I've began.
Now I have Olympia D.R.H. mix between EVO R-2 and TEAM (full susp, skareb
front susp).
Olympia web site is under construction, so there are no pictures
http://www.olympiacicli.it/prodotti.htm
e-mail me (is your e-mail address real?) so I can send you a pic of the bike
:) and we don't clutter the thread

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rhand.com

Mountain Bikn' Guy said:
Do you ride? What kind of bike?
 
Back
Top