Invoke Problem

  • Thread starter Thread starter Robert Bouillon
  • Start date Start date
R

Robert Bouillon

I have a worker thread that calls MyForm.Invoke(MyEventDelegate), however
once the code hits the invoke method, the thread dies.

Try/Catch doesn't even catch an exception.

Any ideas? I'm using .NET CF SP2

Thanks

--ROBERT
 
Nevermind. Apparantly SP2 has to be installed manually on the emulator.
You'd think that would be in the readme or something....


--ROBERT
 
In .NET CF, you must use "EventHandler" delegate for "Form.Invoke" method.

You could make a simple EventDispatcher to dispatcher the job with custom
delegate and event arguments.

I wrote a handy dispatcher for synchronizing events between worker thread
and form thread. The code is adhered below:

*** START of EventDispatcher.cs ***
using System;
using System.Windows.Forms;

namespace MyApplication {
public sealed class EventDispatcher {
public static void Invoke( Control control, EventHandler handler, object
sender, EventArgs args ) {
control.Invoke( new EventHandler( new EventDispatcher( handler, sender,
args ).ProxyHandler ) );
}

private EventDispatcher( EventHandler realHandler, object sender,
EventArgs args ) {
this._realHandler = realHandler;
this._sender = sender;
this._args = args;
}

private EventHandler _realHandler;
private object _sender;
private EventArgs _args;

private object Sender {
get { return( this._sender ); }
}

private EventArgs Args {
get { return( this._args ); }
}

private EventHandler RealHandler {
get { return( this._realHandler ); }
}

private void ProxyHandler( object sender, EventArgs args ) {
this.RealHandler( this.Sender, this.Args );
}
}
}
*** END ***

Hope it helps.


Compulim @ kasuei
 
Back
Top