Ejemplo n.º 1
0
        private void UpdateStates(StateSnapshot states)
        {
            this.UpdateStatusRows(states);
            this.UpdateLogRows(states.AllPeerGroups);

            // This isn't a dependency property, so we can't bind to it. We have to manually update it.
            TimeSpan monitored = this.stateManager.Monitored;

            monitored = ConvertUtility.RoundToSeconds(monitored);
            this.monitoredTime.Text = monitored.ToString();

            // Optionally, simulate a failure when ScrollLock is toggled on.
            this.simulateFailure = this.CommonOptions.ScrollLockSimulatesFailure && Keyboard.IsKeyToggled(Key.Scroll);
        }
Ejemplo n.º 2
0
 private void BackgroundTimerCallback(object state)
 {
     // Only let one Update run at a time. If the callback takes longer than 1 second, it will be invoked again from another thread.
     if (!this.closing && Interlocked.CompareExchange(ref this.updatingLock, 1, 0) == 0)
     {
         try
         {
             StateSnapshot states = this.stateManager.Update(this.simulateFailure);
             this.Dispatcher.BeginInvoke(new Action(() => this.UpdateStates(states)));
         }
         finally
         {
             Interlocked.Exchange(ref this.updatingLock, 0);
         }
     }
 }
Ejemplo n.º 3
0
        private void BackgroundTimerCallback(object state)
        {
            // Only let one Update run at a time. If the callback takes longer than 1 second, it will be invoked again from another thread.
            if (!this.closing && Interlocked.CompareExchange(ref this.updatingLock, 1, 0) == 0)
            {
                try
                {
                    StateSnapshot states = this.stateManager.Update(this.simulateConnection);
                    this.Dispatcher.BeginInvoke(new Action(() => this.UpdateStates(states)));
                }
#pragma warning disable CA1031 // Do not catch general exception types. Timer callback has to catch all to prevent program termination.
                catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    // If we don't handle all exceptions here, then the app will go away and log a .NET Runtime error in the event log like:
                    // "The process was terminated due to an unhandled exception."
                    Log.Error(this.GetType(), "An unhandled exception occurred on the background timer thread.", ex);
                }
                finally
                {
                    Interlocked.Exchange(ref this.updatingLock, 0);
                }
            }
        }