public static void TestThread(object Dots) { Route route = new Route(10); route = route.Load(Dots as PointD[]); if (route != null) { string RouteLength = route.RouteLength; // Длина в метрах string RouteJamsTime = route.RouteJamsTime; // Время проезда в секундах с учетом пробок string RouteTime = route.RouteTime; // Время проезда в секундах string RouteHumanLength = route.RouteHumanLength; // Возвращает строковое представление длины маршрута с единицами измерения. string RouteHumanJamsTime = route.RouteHumanJamsTime; // Возвращает строковое представление времени проезда маршрута с единицами измерения с учетом пробок. string RouteHumanTime = route.RouteHumanTime; // Возвращает строковое представление времени проезда маршрута с единицами измерения. Console.WriteLine("---------------------------"); Console.WriteLine(RouteLength); Console.WriteLine(RouteJamsTime); Console.WriteLine(RouteTime); Console.WriteLine(RouteHumanLength); Console.WriteLine(RouteHumanJamsTime); Console.WriteLine(RouteHumanTime); Console.WriteLine("---------------------------"); } }
public Route Load(PointD[] RoutePoints) { using (WebBrowser webBrowser = new WebBrowser()) { ScriptManager scriptManager = new ScriptManager(); webBrowser.ScriptErrorsSuppressed = true; webBrowser.ObjectForScripting = scriptManager; webBrowser.WebBrowserShortcutsEnabled = false; scriptManager.GetState = ScriptManager.State.Running; string jsCode = GetJSCode(RoutePoints); webBrowser.DocumentText = String.Format(htmlTemplate, jsCode); bool IsCheck = true; DateTime starTime = DateTime.Now; while (IsCheck) { switch (scriptManager.GetState) { case ScriptManager.State.Ok: Route route = new Route(); route.RouteId = Guid.NewGuid().ToString(); route.RouteLength = scriptManager.routeLength; route.RouteJamsTime = scriptManager.routeJamsTime; route.RouteTime = scriptManager.routeTime; route.RouteHumanLength = scriptManager.routeHumanLength; route.RouteHumanJamsTime = scriptManager.routeHumanJamsTime; route.RouteHumanTime = scriptManager.routeHumanTime; IsCheck = false; return route; case ScriptManager.State.Error: IsCheck = false; break; } // Выходим по TimeOut TimeSpan ts = DateTime.Now - starTime; if (ts.Seconds > requestTimeout) { IsCheck = false; } Thread.Sleep(100); Application.DoEvents(); } webBrowser.Dispose(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } return null; }