开发者

Requested Clipboard operation did not succeed

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)
   开发者_如何学Goat 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.


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.


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.


EASY! I had the same issue and fixed it.

Just open Task Manager, search for rdpclip.exe under Processes, kill it. Then, open a new task and run it again.


I had this problem with an app but only when running it on an HP mini.

If I have C# express running so I can check the exception,

shutting down Google Chrome removes the problem.

reopening Google Chrome causes it to reappear.

But on my main 64 bit machine, no problem; and on my previous 32 bit machine, no problem either. Side effect of limited RAM perhaps?

Gerald


It's some other application is using Clipboard now. Find out the application monitoring Clipboard and kill the process. Works for me.


If you are using some VNC program (RealVNC) and your application use Clipboard from System.Windows.Forms.dll on main thread "The requested clipboard operation failed" will occur. This is my solution written in C# for .NET 3.5:

using System.Threading;

   var dataObject = new DataObject();
   private Clipboard()
   {
        //dataObject logic here

        Thread clipboardThread = new Thread(new ThreadStart(GetClipboard));
        clipboardThread.SetApartmentState(ApartmentState.STA);
        clipboardThread.Start();
   }

   private void GetClipboard()
   {
         Clipboard.SetDataObject(dataObject, true, 10, 100);
   }


I used System.Windows.Forms.Control.WndProc method and PostMessage.

string clipboardText;

{
    clipboardText = "TEXT FOR CLIPBOARD";
    PostMessage(Handle, CLIPBOARD_BACKUP_MSG, 0, 0);
}

protected override void WndProc(ref Message m) 
{
    if (m.Msg == CLIPBOARD_BACKUP_MSG)
    {
        Clipboard.SetText(clipboardText);
    }

    base.WndProc(ref m);
}


I had this problem too, and use this code as WireGuy answered. but this code code makes an exception in my PC "Requested Clipboard operation did not succeed". I put this line a Try Catch statement

            try
            {
                Clipboard.SetDataObject(textBoxCodePan.Text, true, 10, 100);
            }
            catch (Exception)
            {

            }

and did work correctly.


Try running GetDataObject in while loop with Try catch. Eventually it will succeed.

    while (tempObj == null)
    {// get from the clipboard
        try
        {
            tempObj = Clipboard.GetDataObject();
        }
        catch (Exception excep)
        {

        }
    }


For myself, I found that the clipboard was still processing my request while I was putting a new one. SendKeys.SendWait("^c"); Clipboard.GetText();

So I added Sleep and it now works great. SendKeys.SendWait("^c"); Thread.Sleep(250); Clipboard.GetText();


For some reason i got "Requested Clipboard operation did not succeed" exceptions every time when running

Dim s = "test"
Clipboard.SetDataObject(s, True, 10, 200)

But

Dim s = "test"
Clipboard.ContainsText()
Clipboard.SetDataObject(s, True, 10, 200)

worked every time.

However, interestingly

Try
    Dim s = "test"
    Clipboard.SetDataObject(s, True, 10, 200)
catch ex as exception
    Dim s = "test"
    Clipboard.ContainsText()
    Clipboard.SetDataObject(s, True, 10, 200)
end try

will fail on both SetDataObject calls

I'm sure its as transient error as i was setting clipboard content the other day without issue.


I suddenly had this error when copying data from Microsoft SQL Server Management Studio, since then I couldn't copy anything. Restarting explorer.exe process solved the issue. I guess the explorer process handles most of the clipboard action.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜