Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.Routes.FindShortestRouteBetweenAsync C# (CSharp) Method

FindShortestRouteBetweenAsync() public method

public FindShortestRouteBetweenAsync ( string fromCity, string toCity, TransportModes mode, IProgress reportProgress ) : Task>
fromCity string
toCity string
mode TransportModes
reportProgress IProgress
return Task>
        public Task<List<Link>> FindShortestRouteBetweenAsync(string fromCity, string toCity,
                                                   TransportModes mode, IProgress<string> reportProgress)
        {
            return Task.Run(() =>
                            FindShortestRouteBetween(fromCity, toCity,
                                                     mode, reportProgress)
                );
        }

Usage Example

        public async Task TestFindShortestRouteBetweenAsyncProgress()
        {
            var cities = new Cities();
            cities.ReadCities(CitiesTestFile);

            var routes = new Routes(cities);
            routes.ReadRoutes(LinksTestFile);

            // do synchronous execution
            var linksExpected = routes.FindShortestRouteBetween("Basel", "Zürich", TransportMode.Rail);

            // do asynchronous execution
            var messages = new List<string>();
            var progress = new Progress<string>(msg => messages.Add(msg));
            var linksActual = await routes.FindShortestRouteBetweenAsync("Basel", "Zürich", TransportMode.Rail, progress);

            // let pending tasks execute
            await Task.Yield();

            // ensure that at least 5 progress calls are made
            Assert.IsTrue(messages.Distinct().Count()>=5, "Less than 5 distinct progress messages");

            // ensure that all progress messages end with " done"
            Assert.IsTrue(messages.All(m => m.EndsWith(" done")),
                string.Format("Progress message \"{0}\" does not end with \" done\"",
                    messages.FirstOrDefault(m => !m.EndsWith(" done"))));
        }
All Usage Examples Of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.Routes::FindShortestRouteBetweenAsync