PC Review


Reply
Thread Tools Rate Thread

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

 
 
Paul Tomlinson
Guest
Posts: n/a
 
      3rd Feb 2005
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.


 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      3rd Feb 2005
Paul Tomlinson <(E-Mail Removed)> wrote:
> 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?


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.pobox.com/~skeet/csharp/threads/

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QnJ1Y2UgSm9obnNvbiBbQyMgTVZQXQ==?=
Guest
Posts: n/a
 
      3rd Feb 2005
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.


"Paul Tomlinson" wrote:

> 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.
>
>
>

 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      3rd Feb 2005
<"=?Utf-8?B?QnJ1Y2UgSm9obnNvbiBbQyMgTVZQXQ==?=" <Bruce Johnson [C#
MVP]@discussions.microsoft.com>> wrote:
> 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.


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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      3rd Feb 2005
Just currious but, why do you want to execute a method on a specific thread?

Willy.


"Paul Tomlinson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Single-thread delegate vs multi-thread delegate Curious Microsoft Dot NET 3 5th May 2010 03:12 AM
send msg to user who has delegate, but dont want delegate to msg =?Utf-8?B?U3Vuc2hpbmUxMmI=?= Microsoft Outlook Discussion 1 19th May 2006 05:53 PM
Keep Sub Main running while a thread executes pmclinn Microsoft VB .NET 1 16th Jun 2005 06:44 PM
Shut down thread - thread closes form, form doesn't close because thread calls it etc... Robin Tucker Microsoft VB .NET 4 17th Oct 2003 12:03 PM
Re: AcceptChanges hangs when executes outside main thread Chris Tacke, eMVP Microsoft Dot NET Compact Framework 2 26th Jul 2003 01:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:00 PM.