InvokeRequired?

  • Thread starter Thread starter JohnL
  • Start date Start date
J

JohnL

I was trying to port my existing code and found that InvokeRequired
property which exists in Framework 1.1 does not exist in Compact
Framework. Are there any workarounds?
 
You could store the UI thread in a Thread variable, when you have the need
to test for InvokeRequired, check if the CurrentThread is the thread you
stored and that is your InvokeRequired result...

Alternatively, design your code so it doesn't need to check for
InvokeRequired (maybe it just luck, but all my code knows whether it is on a
worker thread or the UI thread given the context and no variable checks).

Either way, not that using Invoke when it is not required is fairly
inexpensive so when in doubt... Invoke.

Cheers
Daniel
 
I've added this feature to the SDF's ControlEx class. Now it has
ControlEx.InvokeRequired property and also static method
ControlEx.InvokeRequiredForControl.

Instead of this.InvokeRequired now have to write something like this:

void SafeFunction(object sender, System.EventArgs e)
{
if (ControlEx.InvokeRequiredForControl(this))
{
this.Invoke(new EventHandler(SafeFunction));
return;
}

label1.Text = "Updated";
}

HTH
 
What is the type of the ControlEx object?

Sergey Bogdanov said:
I've added this feature to the SDF's ControlEx class. Now it has
ControlEx.InvokeRequired property and also static method
ControlEx.InvokeRequiredForControl.

Instead of this.InvokeRequired now have to write something like this:

void SafeFunction(object sender, System.EventArgs e)
{
if (ControlEx.InvokeRequiredForControl(this))
{
this.Invoke(new EventHandler(SafeFunction));
return;
}

label1.Text = "Updated";
}

HTH

--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

I was trying to port my existing code and found that InvokeRequired
property which exists in Framework 1.1 does not exist in Compact
Framework. Are there any workarounds?
 
ControlEx. It's a class derived frrom Control.

http://www.opennetcf.org/library/OpenNETCF.Windows.Forms.ControlEx.html

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate


SMeddows said:
What is the type of the ControlEx object?

Sergey Bogdanov said:
I've added this feature to the SDF's ControlEx class. Now it has
ControlEx.InvokeRequired property and also static method
ControlEx.InvokeRequiredForControl.

Instead of this.InvokeRequired now have to write something like this:

void SafeFunction(object sender, System.EventArgs e)
{
if (ControlEx.InvokeRequiredForControl(this))
{
this.Invoke(new EventHandler(SafeFunction));
return;
}

label1.Text = "Updated";
}

HTH

--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

I was trying to port my existing code and found that InvokeRequired
property which exists in Framework 1.1 does not exist in Compact
Framework. Are there any workarounds?
 
Back
Top