private void WriteToClipboard(string stringToWrite)
{
bool written = false;
while (!written)
{
try
{
System.Windows.Forms.Clipboard.SetText(stringToWrite);
written = true;
}
catch (System.Runtime.InteropServices.ExternalException)
{
written = false;
}
catch
{
written = true;
}
}
}