Bug 5734 - Calling "StopListening()" on Geolocator causes NRE when not started
Summary: Calling "StopListening()" on Geolocator causes NRE when not started
Status: RESOLVED FIXED
Alias: None
Product: Mobile API (Preview)
Classification: Xamarin
Component: Windows Phone ()
Version: Preview
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Eric Maupin
URL:
Depends on:
Blocks:
 
Reported: 2012-06-19 05:30 UTC by Peter Theill
Modified: 2012-07-16 22:01 UTC (History)
0 users

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Peter Theill 2012-06-19 05:30:52 UTC
When you initializes a Geolocator and tries to call "StopListening()" on it before "StartListening()" is called it will cause a NRE.

var watcher = new Geolocator();
watcher.StartListening(1000, 10);

// works
watcher.StopListening();

but


var watcher = new Geolocator();

// causes a NRE
watcher.StopListening();


I think the StopListening() method should be changed to:


    public void StopListening()
    {
      if (!IsListening) {
        return;
      }

      this.watcher.PositionChanged -= new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(this.WatcherOnPositionChanged);
      this.watcher.Stop();
      this.watcher.Dispose();
      this.watcher = (GeoCoordinateWatcher) null;
    }

This will not thrown an error in case you're not listening or if you have called stop listening multiple times.
Comment 1 Eric Maupin 2012-07-16 22:01:18 UTC
This is fixed and the update is available: http://xamarin.com/mobileapi