private static int GetTabExpansionTimeout()
        {
            try
            {
                using (var key = Registry.CurrentUser.OpenSubKey(PowershellConsoleKey))
                {
                    if (key != null)
                    {
                        // 'TabExpansionTimeout' key should be a DWORD, so, simply cast it to int
                        // If the cast fails, log a message and move on
                        var value = key.GetValue(TabExpansionTimeoutKey, DefaultTabExpansionTimeout, RegistryValueOptions.None);

                        if (value is int)
                        {
                            return(Math.Min((int)value, 1));
                        }
                        else
                        {
                            ActivityLog.LogWarning(ExceptionHelper.LogEntrySource,
                                                   string.Format(CultureInfo.CurrentCulture, Resources.RegistryKeyShouldBeDWORD, TabExpansionTimeoutKey));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Ignore all other exceptions, such as SecurityException
                ActivityLog.LogWarning(ExceptionHelper.LogEntrySource, ex.ToString());
            }

            return(DefaultTabExpansionTimeout);
        }
        private void ScheduleErrorCheck(int sampleIntervalMs)
        {
            var errorCheckTask =
                Task.Delay(sampleIntervalMs)
                .ContinueWith(_ => CheckForErrors(), _stopMonitoringToken.Token, TaskContinuationOptions.None, _taskScheduler);

            errorCheckTask.ContinueWith(task =>
            {
                Debug.Assert(task.Exception != null, "A failed task should have an exception");
                task.Exception.Flatten().Handle(e =>
                {
                    ActivityLog.LogWarning(Constants.ApplicationName, string.Format("Got an error while checking the error tasks, error: {0}", e));
                    return(true);
                });
            }, TaskContinuationOptions.OnlyOnFaulted);

            errorCheckTask.ContinueWith(_ => ScheduleErrorCheck(sampleIntervalMs), _stopMonitoringToken.Token);
        }