请求的剪贴板操作未成功
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)
我用谷歌搜索了这个,但我无法得到关于为什么会发生这种情况的正确答案。
MSDN 文档称,当用户切换到另一个应用程序时,这种情况经常发生,但事实似乎并非如此。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
有类似的问题。找到此条目 ,
基本上就是说在调用中将
retryTimes
设置为 2:去尝试一下。如果有人可以发布可重现的测试用例,那就太好了。
Having a similar problem. Found this entry,
which basically says to set
retryTimes
to 2 in the call:Going to try it. Would be nice if anyone could post a reproducible test case.
根本原因可能是您正在执行两项操作,通常是复制和粘贴,并假设剪贴板可用。发生的情况是,您进行复制(以更新剪贴板),然后当您尝试粘贴时其他剪贴板查看器会对它做出反应。防御方法是在粘贴操作周围有一个例外/睡眠/重试机制,以便您可以优雅地处理它。告诉用户关闭 rpdclip 等,在生产应用程序中是行不通的。
还要确保您没有将剪贴板用作拐杖。提供剪贴板是为了方便用户,而不是程序员。
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.
简单的!我有同样的问题并解决了它。
只需打开任务管理器,在
进程
下搜索rdpclip.exe
,将其杀死。然后,打开一个新任务并再次运行它。EASY! I had the same issue and fixed it.
Just open Task Manager, search for
rdpclip.exe
underProcesses
, kill it. Then, open a new task and run it again.我在使用某个应用程序时遇到了这个问题,但仅在 HP mini 上运行该应用程序时遇到。
如果我正在运行 C# Express,以便可以检查异常,
则关闭 Google Chrome 可以消除该问题。
重新打开 Google Chrome 会导致它重新出现。
但在我的主 64 位机器上,没问题;在我以前的 32 位机器上也没有问题。也许是有限内存的副作用?
杰拉尔德
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.
如果您正在使用某些 VNC 程序 (RealVNC) 并且您的应用程序在主线程上使用 System.Windows.Forms.dll 中的剪贴板,则会发生“请求的剪贴板操作失败”。这是我用 C# 为 .NET 3.5 编写的解决方案:
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:
我遇到了这个问题,这对我有用,在将文本设置到剪贴板(Clipboard.SetText(string Text))之前添加这个,
所以它最终变成
i had this problem and this worked for me , add this before setting text to clipboard (Clipboard.SetText(string Text))
so it finally become
我使用了 System.Windows.Forms.Control.WndProc 方法和 PostMessage。
I used System.Windows.Forms.Control.WndProc method and PostMessage.
我也遇到了这个问题,并使用此代码作为 WireGuy 回答。但此代码在我的电脑中出现异常“请求的剪贴板操作未成功”。我把这一行放在 Try Catch 语句中
并且工作正常。
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
and did work correctly.
尝试在 while 循环中使用 Try catch 运行 GetDataObject。最终它会成功。
Try running GetDataObject in while loop with Try catch. Eventually it will succeed.
就我自己而言,我发现剪贴板仍在处理我的请求,而我
正在放一个新的。
<代码>
SendKeys.SendWait("^c");
Clipboard.GetText();
所以我添加了 Sleep,现在效果很好。
<代码>
SendKeys.SendWait("^c");
线程.睡眠(250);
Clipboard.GetText();
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();
由于某种原因,我每次运行时都会遇到“请求的剪贴板操作未成功”异常,
但
每次都有效。
然而,有趣的是,
两个 SetDataObject 调用都会失败,
我确信它是短暂的错误,就像我前几天设置剪贴板内容时没有问题一样。
For some reason i got "Requested Clipboard operation did not succeed" exceptions every time when running
But
worked every time.
However, interestingly
will fail on both SetDataObject calls
I'm sure its as transient error as i was setting clipboard content the other day without issue.
我在从 Microsoft SQL Server Management Studio 复制数据时突然出现此错误,从那以后我无法复制任何内容。
重新启动 explorer.exe 进程解决了该问题。我猜想资源管理器进程处理大部分剪贴板操作。
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.