How to solve this :Delegates in CF ?

S

Sagaert Johan

Hi

I created a TCPIP class that implements async callbacks , works good in full
framework, but in CF the delegates seem to block my app.

The callbacks (run under a different thread ID since the are async) are
blocking my app.
the toolbar is onder control of the main form thread ,so i can not change
properties of it from another thread.
How to sove this ?

Strange ,if i create the same application onder the full framework, then
there is no problem.

private void OnConnected(object sender, System.EventArgs e,string ip,string
port)
{
toolBar1.Buttons[3].ImageIndex=1;
}



Johan
 
A

Alex Feinman [MVP]

You need to use the Invoke method on one of your controls, e.g. a form to
switch to a UI thread. Keep in mind that the only type of delegate supported
by Control.Invoke in CF 1.0 is EventHandler, so you will have to pass
parameters via a member variable

private void OnConnected(object sender, System.EventArgs e,string ip,string
port)
{
...
newImageIndex = 3;
this.Invoke(new EventHandler(UpdateUI));
...
}

void UpdateUI(object sender, EventArgs)
{
toolBar1.Buttons[3].ImageIndex=newImageIndex;
}
 

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