WPF + cross thread access

In standart dotnet I can use InvokeRequired to see if I need to use Invoke before accessing a control.

How do I do that in standard netmf?

I’m playing with the sample “A Graphing Altimeter” at gadgeteering.net and i ported the gadgeteer driver for the humidity sensor over to standard netmf, but the MeasurementComplete event runs in a different thread and it give an System.InvalidOperationException exception when I try to call Invalidate on a canvas.

I have used this:

if (!Dispatcher.CheckAccess())
1 Like

I think you need something like:

if (!mainWindow.Dispatcher.CheckAccess())

Oh yeah I used in my custom Window derived class.

You can also get to the dispatcher instance using static Dispatcher.CurrentDispatcher

Wouldn’t CheckAccess always return true if you check against the Dispatcher.CurrentDispatcher? You want the dispatcher
for the thread that was used to create the graphic object.

1 Like


That why I would get in main thread and store it for later use.

Ahh, I ripped appart gadgeteer’s CheckAndInvoke but didnt understand what was going on. There is a lot of fluff around it. And this code complained about requiring a static method or something.

This did the trick.

ThanksArchitect and Mike. I have beed struggling with this all evening, and you guys helped me fix it in 15 mins.

You are welcome! Show us some screenshots after you are done.