.Net从剪贴板获取图像,同时其他应用程序正在从中读取/写入?

时间:2021-09-13 22:45:46

I have a .net application that monitors the clipboard every 100ms for an image that is taken from a camera (from a different application) and displays it in a picture box.

我有一个.net应用程序,每隔100毫秒监视剪贴板,以获取从相机(来自不同的应用程序)获取的图像并将其显示在图片框中。

However, occasionally the program that writes the image to the clipboard gets an error saying

但是,偶尔将图像写入剪贴板的程序会出错

"Can't Open Clipboard".  

This only happens when the .net application is monitoring using the following:

这仅在.net应用程序使用以下内容进行监视时发生:

Clipboard.GetDataObject().GetDataPresent(DataFormats.Bitmap)

If I stop the .net application from reading the clipboard I don't get any errors!

如果我停止.net应用程序读取剪贴板,我不会收到任何错误!

I am wondering if anyone has any ideas if there is a better way of going about this.

我想知道是否有人有任何想法,如果有更好的方法来解决这个问题。

2 个解决方案

#1


I was about to tell you that you should register with the clipboard chain, to be notified whenever something changes. But the Clipboard class doesn't seem to implement that. You could, however, use P/Invoke to do that. This article should get you started.

我打算告诉你,你应该注册剪贴板链,以便在出现变化时收到通知。但是Clipboard类似乎没有实现它。但是,您可以使用P / Invoke来执行此操作。这篇文章应该让你入门。

#2


I found this article from vbaccelerator very helpful implementing a clipboard chain hook in .Net

我发现vbaccelerator中的这篇文章非常有用,可以在.Net中实现剪贴板链钩子

#1


I was about to tell you that you should register with the clipboard chain, to be notified whenever something changes. But the Clipboard class doesn't seem to implement that. You could, however, use P/Invoke to do that. This article should get you started.

我打算告诉你,你应该注册剪贴板链,以便在出现变化时收到通知。但是Clipboard类似乎没有实现它。但是,您可以使用P / Invoke来执行此操作。这篇文章应该让你入门。

#2


I found this article from vbaccelerator very helpful implementing a clipboard chain hook in .Net

我发现vbaccelerator中的这篇文章非常有用,可以在.Net中实现剪贴板链钩子