title: How to handle a blocked clipboard and other oddities
body: <p>Over the course of the last couple of hours I have been tracking down a fairly specific bug with that occurs because another application has the clipboard open. Essentially as the clipboard is a shared resource (as per <a href="http://blogs.msdn.com/rds/archive/2006/11/20/why-does-my-shared-clipboard-not-work-part-2.aspx" rel="nofollow noreferrer">"Why does my shared clipboard not work?"</a>) and you attempt to execute</p>
  
  <pre><code>Clipboard.SetText(string)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Clipboard.Clear().
  </code></pre>
  
  <p>The following exception is thrown:</p>
  
  <pre>
  System.Runtime.InteropServices.ExternalException: Requested Clipboard operation did not succeed. 
      at System.Windows.Forms.Clipboard.ThrowIfFailed(Int32 hr)
      at System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean copy, Int32 retryTimes, Int32 retryDelay)
      at System.Windows.Forms.Clipboard.SetText(String text, TextDataFormat format)
      at System.Windows.Forms.Clipboard.SetText(String text)
  </pre>
  
  <p>My initial solution was to retry after a short pause, until I realised that Clipboard.SetDataObject has fields for the number of times and the length of the delay. .NET's default behaviour is to try 10 times with a 100&nbsp;msec delay.</p>
  
  <p>There is one final thing that has been noted by the end user. That is, despite the exception being thrown, the copy to clipboard operation still works. I haven't been able to find any further information about why this may be.</p>
  
  <p>My current solution to the issue is just to silently ignore the exception... is this really the best way?</p>