Handing events in WPF

I have a program I wrote on the ChipworkX that receives events from my GPS.

The problem is that I cannot set WPF UIElement within this event handler, presumably because the event is outside the WPF window’s thread.

Any ideas on how to deal with this?

			GPS = new MicroGPS("COM1", 9600);
			GPS.GPSUpdate +=new GPSUpdateDelegate(GPS_GPSUpdate);

			InitLabel(ref Fix, "Waiting for GPS data");
			InitLabel(ref Lat, "Lat: --");
			InitLabel(ref Lon, "Lon: --");
			
			this.Visibility = Visibility.Visible;
		}

		void  GPS_GPSUpdate(RMCOutput rmc)
		{
			switch (rmc.Fix)
			{
				case FixType.Active:
					Fix.TextContent = "Fix Active";
					break;

				case FixType.Unknown:
				case FixType.Void:
					Fix.TextContent = "No Fix";
					break;
			}

			Lat.TextContent = "Lat: " + rmc.Coords.Latitude.ToString();
			Lat.TextContent = "Lon: " + rmc.Coords.Longitude.ToString();
		}

[quote] #### Exception System.InvalidOperationException - 0x00000000 (3) ####
#### Message:
#### Microsoft.SPOT.Dispatcher::VerifyAccess [IP: 000c] ####
#### Microsoft.SPOT.DispatcherObject::VerifyAccess [IP: 000d] ####
#### Microsoft.SPOT.Presentation.Controls.Text::set_TextContent [IP: 0004] ####
#### Waypointer.Presentation.MainWindow::GPS_GPSUpdate [IP: 0029] ####
#### ChrisSeto.GeoInfoSystems.MicroGPS.MicroGPS::GPSSerialHandle_DataReceived [IP: 018a] ####
#### System.IO.Ports.SerialPort::DataEventHandler [IP: 0012] ####[/quote]

Invoke() ?

something like UIElement.Dispatcher.Invoke

Look at the GHI Graphical Demo
[url]microframeworkprojects.com

DispatcherOperationCallback dispatcherCallback = new DispatcherOperationCallback(delegate(object param)
{
	ChangeSelection((int)param);
	return 0;
})

That’s the problem with WPF. I have had similar with the cobra project. Mark helped me with that by using the dispatcher (as Gus showed)

The problem is that you do not have access. Therefor you will need the dispatcher …

Skew helped me out with this last night. As it turned out there were a few differnt issues at work, like passing the RMCOutput struct.

It’s fixed now. I’ll post code later.

Thanks Skew! ;D