title: Unable to set WinForms clipboard in unit test
body: <p>I'd like to populate the Forms.Clipboard with text from a NUnit test.</p>
  
  <p>The first problem I encountered was that the Clipboard must be used in STA mode. I found <a href="https://stackoverflow.com/questions/2434067/how-to-run-unit-tests-in-stathread-mode">the solution</a> (NUnit 2.5.x+) to set the RequiresSTA attribute on the method.</p>
  
  <p>Next I get an ExternalException when calling Clipboard.SetText(). I found <a href="http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/a23c31df-e645-4500-ab4a-e6178510a9b1" rel="nofollow noreferrer">the solution</a> to use Clipboard.SetDataObject(object, bool, int, int) where you can specify retryTimes to make several attempts to set the clipboard. This hacky solution works <em>sometimes</em>, which obviously isn't good enough (increasing the retryTimes parameter will of course also increase the chance of succeeding).</p>
  
  <p>Others (for instance <a href="https://stackoverflow.com/questions/2434067/how-to-run-unit-tests-in-stathread-mode">Peter</a>) have succeeded with this, so perhaps it has something to do with my environment: I run VS2010 under Windows 7 64-bit targeting .NET 3.5 and x86. The NUnit version is 2.5.9.</p>
  
  <p>I'm stuck. Any help would be appreciated.</p>