Skip to content

Commit

Permalink
Merge pull request Azure-Samples#493 from Azure-Samples/VJTest
Browse files Browse the repository at this point in the history
Fix for intermittent crash when creating ExtendedExecutionSessoin to …
  • Loading branch information
VaijanathB committed Apr 11, 2016
2 parents a6d54f1 + 218855f commit 54723a6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
<SDKReference Include="Microsoft.VCLibs, Version=14.0">
<Name>Visual C++ 2015 Runtime for Universal Windows Platform Apps</Name>
</SDKReference>
<SDKReference Include="SQLite.UWP.2015, Version=3.11.1">
<SDKReference Include="SQLite.UWP.2015, Version=3.12.0">
<Name>SQLite for Universal Windows Platform</Name>
</SDKReference>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,28 +184,38 @@ private async Task BeginExtendedExecution()

ClearExtendedExecution();

var newSession = new ExtendedExecutionSession
try
{
Reason = ExtendedExecutionReason.LocationTracking,
Description = "Tracking your location"
};
newSession.Revoked += SessionRevoked;
ExtendedExecutionResult result = await newSession.RequestExtensionAsync();
switch (result)
{
case ExtendedExecutionResult.Allowed:
session = newSession;
ViewModel.Geolocator.AllowsBackgroundUpdates = true;
ViewModel.StartTrackingTripCommand.Execute(null);
var newSession = new ExtendedExecutionSession
{
Reason = ExtendedExecutionReason.LocationTracking,
Description = "Tracking your location"
};
newSession.Revoked += SessionRevoked;
ExtendedExecutionResult result = await newSession.RequestExtensionAsync();
switch (result)
{
case ExtendedExecutionResult.Allowed:
session = newSession;
ViewModel.Geolocator.AllowsBackgroundUpdates = true;
ViewModel.StartTrackingTripCommand.Execute(null);

break;
break;

default:
Acr.UserDialogs.UserDialogs.Instance.Alert("Unable to execute app in the background.",
"Background execution denied.", "OK");
default:
Acr.UserDialogs.UserDialogs.Instance.Alert("Unable to execute app in the background.",
"Background execution denied.", "OK");

newSession.Dispose();
break;
newSession.Dispose();
break;
}
}
catch (Exception ex)
{
// Sometimes while creating ExtendedExecution session you get Resource not ready exception.
Logger.Instance.Report(ex);
Acr.UserDialogs.UserDialogs.Instance.Alert("Will not be able to execute app in the background.",
"Background execution session failed.", "OK");
}
}

Expand Down Expand Up @@ -371,7 +381,7 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>

private async void DrawPath(BasicGeoposition basicGeoposition)
{
if (!ViewModel.IsRecording || ViewModel.CurrentTrip.Points.Count == 0)
if (!ViewModel.IsRecording || ViewModel.CurrentTrip?.Points?.Count == 0)
return;

await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
Expand All @@ -383,8 +393,12 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Locations =
new List<BasicGeoposition>(
ViewModel.CurrentTrip.Points.Select(
ViewModel.CurrentTrip?.Points?.Select(
s => new BasicGeoposition() { Latitude = s.Latitude, Longitude = s.Longitude }));

// If the viewmodel still has not added this point, then add it locally to the Locations collection.
if (Locations.Count == 0)
Locations.Add(basicGeoposition);
}
else
Locations.Add(basicGeoposition);
Expand Down

0 comments on commit 54723a6

Please sign in to comment.