/// <summary>
        /// Stop the currently running task and set the result.
        /// </summary>
        /// <param name="statusMessage"></param>
        /// <param name="hasErrors"></param>
        /// <param name="hasWarnings"></param>
        /// <param name="resultData"></param>
        public void StopTask(string statusMessage = null, bool hasErrors = false, bool hasWarnings = false, object resultData = null)
        {
            if (_status != ReporterStatusSpecifier.Started)
            {
                return;
            }

            _status = ReporterStatusSpecifier.Stopped;

            _stopwatch.Stop();

            DestroyTimer();

            // Send a message to signal completion.
            if (string.IsNullOrWhiteSpace(statusMessage))
            {
                statusMessage = "Task complete.";
            }

            var taskInfo = new TaskStatusSummary
            {
                IsStarted     = true,
                IsFinished    = true,
                HasErrors     = hasErrors,
                HasWarnings   = hasWarnings,
                StatusMessage = statusMessage,
                Data          = resultData,
                ElapsedTime   = _stopwatch.ElapsedMilliseconds
            };

            QueueMessage(taskInfo);

            // Flush the message queue.
            ProcessQueuedMessages(forceProcessing: true, flushAllItems: true);
        }
        /// <summary>
        /// Start the task.
        /// </summary>
        public void StartTask()
        {
            if (_status == ReporterStatusSpecifier.Started)
            {
                return;
            }

            _status = ReporterStatusSpecifier.Started;

            // Initialize the timer to trigger time-based updates.
            if (_timer != null)
            {
                _timer.Stop();

                _timer.Elapsed -= _timer_Elapsed;
            }

            _stopwatch.Restart();

            // Initialize the SignalR hub and notification message queue.
            _reportQueue = new ConcurrentQueue <ITaskActivityMessage>();

            _messageHub = GlobalHost.ConnectionManager.GetHubContext <TaskActivityMessageHub, ITaskActivityMessageHub>();

            var taskInfo = new TaskStatusSummary
            {
                IsStarted     = true,
                StatusMessage = "Working...",
                ElapsedTime   = 0
            };

            QueueMessage(taskInfo);

            // Initialize the timer for regulating progress notifications.
            // The timer fires once after the initial notification delay, and is then reconfigured for periodic notifications.
            _notificationsAreDelayed = this.StartNotificationDelayMilliseconds > 0;

            if (this.NotifyElapsedTime || _notificationsAreDelayed)
            {
                _timer = new System.Timers.Timer();

                _timer.Interval  = this.StartNotificationDelayMilliseconds;
                _timer.AutoReset = false;

                _timer.Elapsed += _timer_Elapsed;

                _timer.Start();
            }
        }