private async void InternalCalculateRoute(object o) { Route = null; IsCalculating = true; Progress = 0; ShortestDistanceSoFar = 0; CtsRouteCalculation = new CancellationTokenSource(); try { Route = await tripCalculator .CalculateShortestRouteAsync(Start, End, PlacesToVisit.ToArray(), CtsRouteCalculation.Token, new Progress <RouteCalculationProgress>( prg => { Progress = prg.Progress; ShortestDistanceSoFar = prg.ShortestRouteSoFar; })); } catch (OperationCanceledException) { } IsCalculating = false; }
private void InternalClear(object o) { PlacesToVisit.Clear(); Start = End = null; Route = null; calculateRouteCommand.UpdateCanExecute(false); }
private void InternalAddCity(object o) { PlacesToVisit.Add(WayPointToAdd); UpdateCommands(); WayPointToAdd = tripCalculator .Locations .SkipUntil(mpl => mpl.Name == WayPointToAdd.Name) .FirstOrDefault(); OnPropertyChanged("Locations"); }
private void InternalCalculateRoute(object o) { Route = null; IsCalculating = true; Progress = 0; ShortestDistanceSoFar = 0; Route = tripCalculator .CalculateShortestRoute(Start, End, PlacesToVisit.ToArray()); IsCalculating = false; }
private async void InternalCalculateRoute(object o) { Route = null; IsCalculating = true; Progress = 0; ShortestDistanceSoFar = 0; CtsRouteCalculation = new CancellationTokenSource(); try { Task <Trip> bruteForceTask = tripCalculator .CalculateShortestRouteAsync(Start, End, PlacesToVisit.ToArray(), CtsRouteCalculation.Token, new Progress <RouteCalculationProgress>( prg => { Progress = prg.Progress; ShortestDistanceSoFar = prg.ShortestRouteSoFar; })); Task <Trip> imFeelingLuckTask = tripCalculator.ImFeelingLuckyAsync(Start, End, PlacesToVisit.ToArray(), CtsRouteCalculation.Token); Task <Trip> completedTask = await Task.WhenAny(new[] { bruteForceTask, imFeelingLuckTask }); Route = completedTask.Result; CtsRouteCalculation.Cancel(); } catch (OperationCanceledException) { } IsCalculating = false; }