.Invoke for my own objects

F

Frank Rizzo

I tried in the vb group, but no answer. Maybe c# folks can help.

The controls and forms allow you to call their .Invoke method, which
allows you to switch back and process whatever you are processing on the
UI thread.
I'd like to implement .Invoke for my own objects for this type of
scenario below. Is it possible?
|

public class XXX
{
private YYY ObjectThatRunsOnDifferentThread = new YYY();
private delegate void myDelegate(string s);

//handles an event from ||ObjectThatRunsOnDifferentThread object|
| private void SomeEventHandler()
{
this.Invoke(new myDelegate(new ||myDelegate||(ProcessData)), new
object[] {"Data"});
}

private void ProcessData(string s)
{
}
}


|
 
J

Jon Skeet [C# MVP]

Frank Rizzo said:
I tried in the vb group, but no answer. Maybe c# folks can help.

The controls and forms allow you to call their .Invoke method, which
allows you to switch back and process whatever you are processing on the
UI thread.
I'd like to implement .Invoke for my own objects for this type of
scenario below. Is it possible?
|

public class XXX
{
private YYY ObjectThatRunsOnDifferentThread = new YYY();
private delegate void myDelegate(string s);

//handles an event from ||ObjectThatRunsOnDifferentThread object|
| private void SomeEventHandler()
{
this.Invoke(new myDelegate(new ||myDelegate||(ProcessData)), new
object[] {"Data"});
}

private void ProcessData(string s)
{
}
}

Assuming your "main" thread isn't a UI thread (if it is, just forward
the call to Control.Invoke), you need to write some kind of message
pump.

The code at http://www.yoda.arachsys.com/csharp/threads/deadlocks.shtml
may help you - the ConsumerJob method is basically the message pump
loop. (Except you'd put a delegate into the queue and then execute it.)
 

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