Bloom.NavigationIsolator.StartTask C# (CSharp) Method

StartTask() private method

private StartTask ( NavigationTask task ) : void
task NavigationTask
return void
        private void StartTask(NavigationTask task)
        {
            _current = task;
            _startNavigation = DateTime.Now;
            _current.Browser.InstallEventHandlers();
            _current.Browser.Navigated += BrowserOnDocumentCompleted;
            Debug.Assert(_timer == null, "We should have cleaned up any old timer before starting a new task");
            _timer = new Timer();
            _timer.Tick += (sender, args) =>
            {
                if (_current == null)
                {
                    // We somehow got another tick after the need for the timer has passed. Get rid of it.
                    CleanupTimer();
                    return;
                }
                if (!_current.Browser.IsBusy)
                {
                    // browser stopped being busy without notifying us! Pretend it did.
                    BrowserOnDocumentCompleted(null, null);
                }
                if (DateTime.Now - _startNavigation > new TimeSpan(0, 0, 0, 2))
                {
                    // Navigation is taking too long. Sometimes the main window stays busy forerver. Give up.
                    // Enhance: may want to wait a bit longer if nothing is waiting...but remember idle tasks can still be frozen out.
                    ForceDocumentCompleted();
                }
            };
            _timer.Interval = 100;
            _timer.Start();
            _current.Browser.Navigate(_current.Url);
        }