T
Tod Johnson
Hello,
as I know UI should be updated only from the main thread. That's why
I've created ProxyClass [1]. The question - is it normal solution or
maybe there are other, the best suggestions for this problem?
Thnx,
Tod
[1]
public class UIUpdater
{
Control _destinationControl;
object [] _args;
UIUpdate _uiDelegate;
EventHandler _uiDelegateEH;
public UIUpdater(Control c)
{
_destinationControl = c;
}
public static EventHandler CreateProxyEventHandler(Control c,
EventHandler e)
{
return (new UIUpdater(c)).GetProxyEventHandler(e);
}
private EventHandler GetProxyEventHandler(EventHandler e)
{
this._uiDelegateEH = e;
return new EventHandler(InvokerEH);
}
void InvokerEH(object sender, EventArgs e)
{
_uiDelegateEH(this, new EventArgs());
}
}
usage on Form:
ct = new ConnectionThreadCE(r);
ct.Connected += UIUpdater.CreateProxyEventHandler(this, new
EventHandler(ct_Connected));
as I know UI should be updated only from the main thread. That's why
I've created ProxyClass [1]. The question - is it normal solution or
maybe there are other, the best suggestions for this problem?
Thnx,
Tod
[1]
public class UIUpdater
{
Control _destinationControl;
object [] _args;
UIUpdate _uiDelegate;
EventHandler _uiDelegateEH;
public UIUpdater(Control c)
{
_destinationControl = c;
}
public static EventHandler CreateProxyEventHandler(Control c,
EventHandler e)
{
return (new UIUpdater(c)).GetProxyEventHandler(e);
}
private EventHandler GetProxyEventHandler(EventHandler e)
{
this._uiDelegateEH = e;
return new EventHandler(InvokerEH);
}
void InvokerEH(object sender, EventArgs e)
{
_uiDelegateEH(this, new EventArgs());
}
}
usage on Form:
ct = new ConnectionThreadCE(r);
ct.Connected += UIUpdater.CreateProxyEventHandler(this, new
EventHandler(ct_Connected));