Repository: unoplatform/uno
File: src/Uno.UWP/Devices/Geolocation/Geolocator.iOSmacOS.cs (C#)

Code before:
	/// </summary>
	public double MovementThreshold
	{
		get => _movementThreshold;
		set
		{
			_movementThreshold = value;
			if (_locationManager != null)
			{
				if (NativeDispatcher.Main.HasThreadAccess)
				{
					_locationManager.DistanceFilter = value;
				}
				else
				{
					NativeDispatcher.Main.Enqueue(() =>
					{
						if (_locationManager != null)
						{
							_locationManager.DistanceFilter = value;
						}
					}, NativeDispatcherPriority.Normal);
				}
			}
		}
	}

	private void _locationManager_LocationsUpdated(object sender, CLLocationsUpdatedEventArgs e)
	{
		BroadcastStatusChanged(PositionStatus.Ready);
		_positionChangedWrapper.Event?.Invoke(this, new PositionChangedEventArgs(ToGeoposition(e.Locations.Last())));
	}

	partial void StartPositionChanged()
	{
		BroadcastStatusChanged(PositionStatus.Initializing);
	}

	internal CLLocationManager LocationManager => _locationManager;

	public IAsyncOperation<Geoposition> GetGeopositionAsync() => GetGeopositionInternalAsync().AsAsyncOperation();

	public Task<Geoposition> GetGeopositionInternalAsync()

	{
		if (CoreDispatcher.Main.HasThreadAccess)
		{
			BroadcastStatusChanged(PositionStatus.Initializing);
			var location = _locationManager.Location;
			if (location == null)
			{

Review comment (suggestion):
Nitpick: This might keep an outdated value in this scenario:
1. MovementThreshold set to value X from a background thread and the field update is scheduled
2. Before the field update runs, some user code on the UI thread sets MovementThreshold again to Y
3. the scheduled field update runs, and the final value is X and not Y even though the Y update happened later.

Generally, in scenarios like this, I try to keep the value to be updated out of the lambda, and just schedule a "notification" of the update instead of the update itself.

Code after:
	/// </summary>
	public double MovementThreshold
	{
		get => _movementThreshold;
		set
		{
			_movementThreshold = value;
			if (_locationManager != null)
			{
				if (NativeDispatcher.Main.HasThreadAccess)
				{
					_locationManager.DistanceFilter = _movementThreshold;
				}
				else
				{
					NativeDispatcher.Main.Enqueue(() =>
					{
						if (_locationManager != null)
						{
							_locationManager.DistanceFilter = _movementThreshold;
						}
					}, NativeDispatcherPriority.Normal);
				}
			}
		}
	}

	private void _locationManager_LocationsUpdated(object sender, CLLocationsUpdatedEventArgs e)
	{
		BroadcastStatusChanged(PositionStatus.Ready);
		_positionChangedWrapper.Event?.Invoke(this, new PositionChangedEventArgs(ToGeoposition(e.Locations.Last())));
	}

	partial void StartPositionChanged()
	{
		BroadcastStatusChanged(PositionStatus.Initializing);
	}

	internal CLLocationManager LocationManager => _locationManager;

	public IAsyncOperation<Geoposition> GetGeopositionAsync() => GetGeopositionInternalAsync().AsAsyncOperation();

	public Task<Geoposition> GetGeopositionInternalAsync()

	{
		if (CoreDispatcher.Main.HasThreadAccess)
		{
			BroadcastStatusChanged(PositionStatus.Initializing);
			var location = _locationManager.Location;
			if (location == null)
			{