Thread A calls a delegate on Thread B but Thread A executes it!?!?

Thread A calls a delegate on Thread B but Thread A executes it!?!?

Post by Paul Tomli » Sat, 05 Feb 2005 01:00:44


OK, I have a multi-threaded application.
I have a master thread which calls a delegate which I want the child thread
to execute but that is not happening, instead the master thread is running
the code in the delegate function. I know this as I can see the thread
id's.

This is what I *want* to happen

i.e.
(Master Thread:)
this.Invoke( DelegateA )

....

(Child Thread)
private void DelegateFunction()
{
...
}


Is there anyway I can get this to happen?
Ta.
 
 
 

Thread A calls a delegate on Thread B but Thread A executes it!?!?

Post by Jon Skeet » Sat, 05 Feb 2005 03:01:41


Thread B needs to be waiting to receive the work in some form or other.
I have an example of something like this with the producer/consumer
queue in my threading article:
http://www.yqcomputer.com/ ~skeet/csharp/threads/

--
Jon Skeet - < XXXX@XXXXX.COM >
http://www.yqcomputer.com/ ~skeet
If replying to the group, please do not mail me too

 
 
 

Thread A calls a delegate on Thread B but Thread A executes it!?!?

Post by QnJ1Y2UgSm » Sat, 05 Feb 2005 03:07:05

Try doing a DelegateA.BeginInvoke instead of an Invoke. And realize that you
will either need to create a callback method that handle the completion of
the process by calling an EndInvoke, just to clean things up.
 
 
 

Thread A calls a delegate on Thread B but Thread A executes it!?!?

Post by Jon Skeet » Sat, 05 Feb 2005 03:19:47


<"=?Utf-8?B?QnJ1Y2UgSm9obnNvbiBbQyMgTVZQXQ==?=" <Bruce Johnson [C#


That won't call it on a particular thread though - it'll call it on a
threadpool thread. That may be okay, but it may not be.

--
Jon Skeet - < XXXX@XXXXX.COM >
http://www.yqcomputer.com/ ~skeet
If replying to the group, please do not mail me too
 
 
 

Thread A calls a delegate on Thread B but Thread A executes it!?!?

Post by Willy Deno » Sat, 05 Feb 2005 07:09:13

Just currious but, why do you want to execute a method on a specific thread?

Willy.