how can i execute a delegate on the thread that created the object ? (object that is not control )

R

roni

how can i execute a delegate on the thread that created the object ?
(the object is not control, but im looking somthing like the control.invoke
, but to my object)
 
M

Markus Stoeger

roni said:
how can i execute a delegate on the thread that created the object ?
(the object is not control, but im looking somthing like the
control.invoke , but to my object)

I think that's not possible. Control.Invoke() sends a window message to the
control, the message gets picked up in the control's message loop and gets
handled from there. If you have a simple object but no Control or Form, you
have no message loop and thus can't do that.

If you only want to signal another thread that it should start doing
something, you can use the Manual- or AutoResetEvent or Monitor classes.

hth,
Max
 
J

Jon Skeet [C# MVP]

roni said:
how can i execute a delegate on the thread that created the object ?
(the object is not control, but im looking somthing like the control.invoke
, but to my object)

Well, what's the other thread doing? It will have to be waiting for you
(or someone else) to ask it to handle your request. You can't just
hijack a thread and tell it to do something if it's in the middle of
doing something else.

Objects don't automatically know which thread they've been created on,
either.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top