2

iam trying to use the code posted here Clipboard event C#

it does work really great, but while testing, i found out that when copying from some application as example firefox, you will get the event running twice, so if you are saving the copied text to a textfile, or writing them to a textbox in the application, the text copied from firefox will appear twice ?

anybody can help me with this problem ? thanks a lot

Community
  • 1
  • 1
lena2211
  • 21
  • 1
  • There could be lots of reasons for that, the info in your question doesn't help narrow it down. Maybe it shouldn't be a problem if the user types Ctrl+C twice. – Hans Passant May 05 '10 at 13:19

3 Answers3

3

Store the last input, and if the new input is the same as the last, discard ?

Samuel DR
  • 1,215
  • 14
  • 28
  • -1 for ugly work-around. There should only be one event. Ok, deleted the -1, as that just seemed too mean. I concede that this is sometimes useful/necessary. – Chris Thornton May 05 '10 at 21:19
  • As It is only happening with some applications, and the origine of the events is not under his control, why is this approach bad ? I don't think it is bad practise to verify a change in state before executing logic. – Samuel DR May 06 '10 at 08:06
  • it's impossible to examine the clipboard contents without altering the state of the clipboard. You can't examine it without opening it, and that's going to have unintended consequences. You can collide with other apps (likely whatever is double-copying in the first place) and you can trigger delayed rendering requests. – Chris Thornton May 07 '10 at 03:00
0

Try it on a "bare" system to ensure that you aren't getting an "echo" somewhere. There should only be one notification. However, if soemthing else alters the clipboard during the event, you can get two. For example, a clipboard-driven text scrubber.

You can also get multiple events if the app doing the copying does it wrong. Such as when apps open/close the clipboard for each data format (they should not, this is a bug if they do). Try copying from plain old Notepad and see if you "hear" the event twice or not.

Chris Thornton
  • 15,620
  • 5
  • 37
  • 62
0

Do you have any plug-ins runnign within FF? It sounds like you do. Try it on a "bare" system with brand-new FF and nothing else.

Chris Thornton
  • 15,620
  • 5
  • 37
  • 62