473,509 Members | 8,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to re-enter a thread?

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=e...TNGP12.phx.gbl

Here's the most relevant prior post I found (again, no solution):
From: Lior Amar (li*******@hotmail.com)
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
Nov 15 '05 #1
8 2374
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?
--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rhand.com

"Mountain Bikn' Guy" <vc@attbi.com> wrote in message
news:BiiHb.54952$VB2.96149@attbi_s51...
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=e...TNGP12.phx.gbl
Here's the most relevant prior post I found (again, no solution):
From: Lior Amar (li*******@hotmail.com)
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

Nov 15 '05 #2

"Mountain Bikn' Guy" <vc@attbi.com> wrote in message
news:BiiHb.54952$VB2.96149@attbi_s51...
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

Nov 15 '05 #3
Ooooooooohhhh.
Lucky you :-)

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

"Mountain Bikn' Guy" <vc@attbi.com> wrote in message
news:sjjHb.150847$8y1.441143@attbi_s52...
Cannondale Jekyll with Lefty fork.
http://www.cannondale.com/bikes/media/jekyll/
"Miha Markic" <miha at rthand com> wrote in message
news:eC**************@TK2MSFTNGP12.phx.gbl...
BTW, what kind of mounting bike do you have?
--


Nov 15 '05 #4
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.

"Mountain Bikn' Guy" <vc@attbi.com> wrote in message
news:BiiHb.54952$VB2.96149@attbi_s51...
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=e...TNGP12.phx.gbl
Here's the most relevant prior post I found (again, no solution):
From: Lior Amar (li*******@hotmail.com)
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

Nov 15 '05 #5
Do you ride? What kind of bike?

"Miha Markic" <miha at rthand com> wrote in message
news:O3**************@tk2msftngp13.phx.gbl...
Ooooooooohhhh.
Lucky you :-)

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

"Mountain Bikn' Guy" <vc@attbi.com> wrote in message
news:sjjHb.150847$8y1.441143@attbi_s52...
Cannondale Jekyll with Lefty fork.
http://www.cannondale.com/bikes/media/jekyll/
"Miha Markic" <miha at rthand com> wrote in message
news:eC**************@TK2MSFTNGP12.phx.gbl...
BTW, what kind of mounting bike do you have?
--



Nov 15 '05 #6
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.
"gregory_may" <None> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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.

"Mountain Bikn' Guy" <vc@attbi.com> wrote in message
news:BiiHb.54952$VB2.96149@attbi_s51...
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=e...TNGP12.phx.gbl

Nov 15 '05 #7
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=e...TNGP12.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
"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:Ol****************@TK2MSFTNGP09.phx.gbl...

"Mountain Bikn' Guy" <vc@attbi.com> wrote in message
news:BiiHb.54952$VB2.96149@attbi_s51...
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

Nov 15 '05 #8
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" <vc@attbi.com> wrote in message
news:4YqHb.497470$275.1402605@attbi_s53...
Do you ride? What kind of bike?

"Miha Markic" <miha at rthand com> wrote in message
news:O3**************@tk2msftngp13.phx.gbl...
Ooooooooohhhh.
Lucky you :-)

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

"Mountain Bikn' Guy" <vc@attbi.com> wrote in message
news:sjjHb.150847$8y1.441143@attbi_s52...
Cannondale Jekyll with Lefty fork.
http://www.cannondale.com/bikes/media/jekyll/
"Miha Markic" <miha at rthand com> wrote in message
news:eC**************@TK2MSFTNGP12.phx.gbl...
> BTW, what kind of mounting bike do you have?
> --



Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4268
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would...
4
6410
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
1
4079
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
4
18514
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function...
1
3687
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with...
10
4196
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
8
4396
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
8
3645
by: Lothar Scholz | last post by:
Because PHP5 does not include the mysql extension any more is there a chance that we will see more Providers offering webspace with Firebird or Postgres Databases ? What is your opinion ? I must...
1
3622
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id ...
3
3468
by: presspley | last post by:
I have bought the book on advanced dreamweaver and PHP recently. I have installed MySQL and PHP server but am getting an error on the $GET statement show below. It says there is a problem with...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.