Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requested Clipboard operation did not succeed

Tags:

Exception Type: ExternalException  Message: Requested Clipboard operation did not succeed.  Method: ThrowIfFailed  Source: System.Windows.Forms    Stack Trace:     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)    at Deerfield.Base.Controls.DataGridView.ProcessCmdKey(Message& msg, Keys keyData) in C:\Users\Developer\Desktop\deerfield\src\core\Deerfield\Deerfield.Base\Controls\DataGridView.cs:line 555    at System.Windows.Forms.Control.ProcessCmdKey(Message& msg, Keys keyData)    at System.Windows.Forms.Control.ProcessCmdKey(Message& msg, Keys keyData)    at System.Windows.Forms.TextBoxBase.ProcessCmdKey(Message& msg, Keys keyData)    at System.Windows.Forms.Control.PreProcessMessage(Message& msg)    at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)    at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg) 

I googled this, but I cannot get a decent answer as to why this is happening.

The MSDN documentation says that this often happens when the user switches to another application, but it does not appear that this was the case.

like image 339
KristenApril Avatar asked Apr 18 '11 19:04

KristenApril


2 Answers

Having a similar problem. Found this entry, which basically says to set retryTimes to 2 in the call:

Clipboard.SetDataObject(object data, bool copy, int retryTimes, int retryDelay) 

Going to try it. Would be nice if anyone could post a reproducible test case.

like image 126
WireGuy Avatar answered Oct 18 '22 09:10

WireGuy


The root cause is likely to be that you are doing two operations, typically a copy and a paste, and assume that the clipboard will be available. What happens is, that you do a copy (to update the clipboard) and then other clipboard viewers are reacting to it when you try to paste. The defense is to have an except/sleep/retry mechanism around the paste operation, so that you can handle it gracefully. Telling the user to shut down rpdclip and such, won't fly in a production application. Also make sure that you're not (ab)using the clipboard as a crutch. The clipboard is provided for the convenience of the USER, not the PROGRAMMER.

like image 44
Chris Thornton Avatar answered Oct 18 '22 09:10

Chris Thornton