title: Detecting Idle status and Logging user out (WinForms)
body: <p>I am currently developing a system that has need for a session time out like subsystem. It is a compact framework 3.5 application, but the principles are very similar to WinForms, so most Winforms solutions will likely work.</p>
  
  <p>Here is the deal, I would like a way to throw an event which lets the MainForm, which is controlling the show, know that the user has not done anything for 20m, so call the logout function and return to the Login form.</p>
  
  <p>This is a "ROUGH" implementation of what I am thinking of. To me, this seems like it smells and is far too simplistic since it assumes ALL activity is routed through a button. I think there must be a way for either the application or the system to know when it is being interacted with.</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      private FlowBase CurrentFlow { get; set; }
  
      private TimerService _service;
      private TimerService CurrentTimerService
      {
          get { return _service ?? (_service = new TimerService()); }
      }
  
      private TimeSpan _allowedInactivityTime = TimeSpan.FromSeconds(10);
      private TimeSpan _currentInactivityTime = TimeSpan.FromSeconds(0);
  
      public MainWindow()
      {
          InitializeComponent();
          GoToMainMenu();
  
          CurrentTimerService.OnTick += (increment) =&gt;
                                          {
                                              if (_currentInactivityTime &gt;= _allowedInactivityTime)
                                              {
                                                  ResetInactivityTimer();
                                                  GoToMainMenu();
                                              }
  
                                              _currentInactivityTime = _currentInactivityTime.Add(increment);
                                          };
      }
  
      private void ResetInactivityTimer()
      {
          _currentInactivityTime = TimeSpan.FromSeconds(0);
      }
  
      private void btnExit_Click(object sender, RoutedEventArgs e)
      {
          if (ccContent.Content is MainMenu)
              Close();
          else
              CurrentFlow.ExitFlow();
      }
  
      private void btnNext_Click(object sender, RoutedEventArgs e)
      {
          ResetInactivityTimer();
          ccContent.Content = CurrentFlow.Process(null);
      }
  
      private void GoToMainMenu()
      {
          var mm = new MainMenu();
          mm.OnFlowSelected += (flow) =&gt;
          {
              CurrentFlow = flow;
              CurrentFlow.OnExit += GoToMainMenu;
              ccContent.Content = flow.Initialize();
          };
  
          ccContent.Content = mm;
      }
  }
  </code></pre>
  
  <p>Thanks in advance for any help</p>