Every so often I get an object disposed exception when shutting down my application.
It happens in my code on the hits the invoke line
void gps_PositionChanged(object sender, EventArgs e)
{
if (gps == null)
{
return;
}
this.Invoke(new UpdateFixStatusDelegate(UpdateFixStatus), gps.IsValid);
// Bug out of GPS values invalid
if (!gps.IsValid)
{
return;
}
Then before returning I do some basic spatial maths to see if point needs to be logged.
}
I initialise the GPS here
private void frmMain_Load(object sender, EventArgs e)
{
// Register the callbacks for GPS
gps.PositionChanged += new EventHandler(gps_PositionChanged);
.........
Shut everything down here
private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// Stop any GPS communications
gps.PositionChanged -= new EventHandler(gps_PositionChanged);
gps.Close();
}
More Information
Running software on WIndows Mobile 6.5 Professional device an HTC Touch Pro II
I built the GPSReader Sample application using InTHeHand V 4.0 and it appears to have the same sort of issue.
private void gps1_PositionChanged(object sender, EventArgs e)
{
" at System.Windows.Forms.Control.InvokeHelper(Delegate method, Boolean fSynchronous, Object[ rgobjArgs)\r\n at System.Windows.Forms.Control.Invoke(Delegate method)\r\n at GpsReader.GpsForm.gps1_PositionChanged(Object sender, EventArgs e)\r\n at InTheHand.WindowsMobile.Gps.Gps.Worker()\r\n"
I then added HDoP display to the form as the value that was being displayed in another application was odd.
private void PositionChanged()
{
lblLat.Text = gps1.Latitude.ToString();
lblLon.Text = gps1.Longitude.ToString();
lblAlt.Text = gps1.AltitudeWRTSeaLevel.ToString();
lblHDoP.Text = gps1.HorizontalDilutionOfPrecision.ToString();
}
The HDoP value seemed to regularly toggle from 666.6 to a reasonable looking value.