B
bob laughland
From within our C# .NET 3.5 WPF application I have this code below.
Basically all it does is you pass it some text, and it is written to
the clipboard.
It works fine for me, but my tester gets this exception
'OpenClipboard Failed (Exception from HRESULT: 0x800401D0
(CLIPBRD_E_CANT_OPEN)'
After he told me about that exception I made the code try again 5
times, and catch the exception, but he now always get the message at
the bottom that says 'here seems to be a problem with the clipboard.
Please try again'
Am I doing something silly here? What are your thoughts?
public static void SetText(Window owner, string clipboardText)
{
int attempts = 0;
while (attempts < 5)
{
try
{
Clipboard.SetText(clipboardText);
return;
}
catch (COMException)
{
Thread.Sleep(10);
attempts++;
}
}
MessageBox.Show(owner, "There seems to be a problem with
the clipboard. Please try again", "Clipboard Error.",
MessageBoxButton.OK, MessageBoxImage.Error);
}
Basically all it does is you pass it some text, and it is written to
the clipboard.
It works fine for me, but my tester gets this exception
'OpenClipboard Failed (Exception from HRESULT: 0x800401D0
(CLIPBRD_E_CANT_OPEN)'
After he told me about that exception I made the code try again 5
times, and catch the exception, but he now always get the message at
the bottom that says 'here seems to be a problem with the clipboard.
Please try again'
Am I doing something silly here? What are your thoughts?
public static void SetText(Window owner, string clipboardText)
{
int attempts = 0;
while (attempts < 5)
{
try
{
Clipboard.SetText(clipboardText);
return;
}
catch (COMException)
{
Thread.Sleep(10);
attempts++;
}
}
MessageBox.Show(owner, "There seems to be a problem with
the clipboard. Please try again", "Clipboard Error.",
MessageBoxButton.OK, MessageBoxImage.Error);
}