.Invoke for my own objects

  • Thread starter Thread starter Frank Rizzo
  • Start date Start date
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)
{
}
}


|
 
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.)
 
Back
Top