title: Best Way to Invoke Any Cross-Threaded Code?
body: <p>I know that this question has been asked before, but I'm looking for a way to:</p>
  
  <ol>
  <li>streamline the creation of safe cross-threaded code.</li>
  <li>reuse this code in any situation (no Windows Forms references).</li>
  </ol>
  
  <p>Here's what I have so far, but I want to remove the Windows Forms references. Any ideas?</p>
  
  <pre><code>public delegate void SafeInvokeDelegate(System.Action action);
  public class SafeInvoke
  {
      private readonly System.Windows.Forms.Control _threadControl;
  
      public SafeInvoke()
      {
          _threadControl = new System.Windows.Forms.Control();
      }
  
      public void Invoke(System.Action action)
      {
          if (_threadControl.InvokeRequired)
              _threadControl.Invoke(new SafeInvokeDelegate(Invoke), new object[] {action});
          else if (action != null) action();
      }
  }
  </code></pre>
  
  <p>The above class might be used this way:</p>
  
  <pre><code>SafeInvoke _safeInvoker = new SafeInvoke();
  void SafeClearItems()
  {
      _safeInvoker.Invoke(delegate
          {
              listView1.Items.Clear();
          });
  }
  </code></pre>
  
  <p>How would I remove the System.Windows.Forms.Control in the SafeInvoke class but keep the same functionality?</p>