I'm developing a Windows Mobile app (Compact Framework 2.0 SP1) and this code it's generating me an error:
public Image Imagen
{
get
{
return imagen;
}
set
{
imagen = value;
this.Invalidate();
}
}
The code is called from a new thread. I've tried to solve using **InvokeRequired:
public Image Imagen
{
get
{
return imagen;
}
set
{
imagen = value;
if (this.InvokeRequired)
this.Invoke(this.Invalidate);
else
this.Invalidate();
}
}
But the line this.Invoke(this.Invalidate); doesn't compile. How can I solve the problem? The first error is that you can interact with controls created on another thread.
Thank you!
Invalidate doesn't need an invoke.
The invalidate only includes a paint message to be processed by the main thread with the rest of the pending messages. But the paint is not done when you call to invalidate and the control is not changed by this thread, so you don't need to use an invoke for it.
If you need to ensure that the control is refreshed, maybe the invalidate is not enough and you need to call to the update too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With