473,395 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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.
Nov 16 '05 #1
4 1179
Paul Tomlinson <ru************@hotmail.com> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
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.

Nov 16 '05 #3
<"=?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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Just currious but, why do you want to execute a method on a specific thread?

Willy.
"Paul Tomlinson" <ru************@hotmail.com> wrote in message
news:ON*************@TK2MSFTNGP15.phx.gbl...
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.

Nov 16 '05 #5

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

Similar topics

1
by: Grandma Wilkerson | last post by:
My question concerns the documentation for Control.BeginInvoke(). At one point is says: "Executes the specified delegate asynchronously with the specified arguments, on the thread that the...
3
by: David Sworder | last post by:
This message was already cross-posted to C# and ADO.NET, but I forgot to post to this "general" group... sorry about that. It just occured to me after my first post that the "general" group readers...
5
by: Marina | last post by:
Hi, we have an app, that executes jobs submitted from an outside application. It executes them asynchronusly, by creating a delegate to the method that can run the job, and calling BeginInvoke on...
2
by: rob | last post by:
Dear All, I am getting an error "Illegal cross-thread operation". I am not creating any threads. I know internally there are many threads running, though. Does that mean that no form can call a...
7
by: Ivan | last post by:
Hi there My work on threads continues with more or less success. Here is what I'm trying to do: Class JobAgent is incharged for some tasks and when it's called it starts thread which performs...
6
by: Simon Verona | last post by:
I would normally use code such as : Dim Customer as new Customer Dim t as new threading.thread(AddressOf Customer.DisplayCustomer) Customer.CustomerId=MyCustomerId t.start Which would create...
3
by: JohnnyGr | last post by:
I have heard theres a new way to start threads with parameters in framework 2.0, does anyone know how to do that? this is what i need to do... Start a thread that executes some stuff, in this...
7
by: Alexander Walker | last post by:
Hello I want to get the value of a property of a control from a thread other than the thread the control was created on, as far as I can see this is not the same as invoking an operation on a...
16
by: Paul Schwann | last post by:
Hi group, I am relatively new to C# (although I have a lot of programming excperience in other languages like Java and C). Currently I am searching for a solution to this problem: Suppose you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.