Willy-Kimura / SharpClipboard

A library for anonymously monitoring clipboard entries.
183 stars 34 forks source link

ClipboardChanged fires for all Types #5

Closed satyris closed 5 years ago

satyris commented 5 years ago

Although SharpClipboard is set to only observe Texts, the event fires if Images/Other file types are copied using latest Version 3.1.0:

_clipboard.ObservableFormats.Texts = true; _clipboard.ObservableFormats.Files = false; _clipboard.ObservableFormats.Images = false; _clipboard.ObservableFormats.Others = false;

Willy-Kimura commented 5 years ago

Seems there might be a recursion issue (with the fail-retry task) in the latest update when an exception occurs causing all the events to be invoked.

Have you tried enabling then disabling monitoring after setting the ObservableFormats using the MonitorClipboard property?

satyris commented 5 years ago

I'm currently using something like this: `public partial class MainWindow { private SharpClipboard _clipboard = new SharpClipboard();

public MainWindow()
{
    _clipboard.InitializeLifetimeService();//Added for testing; didn't change the behavior
    _clipboard.ObservableFormats.Texts = true;
    _clipboard.ObservableFormats.Files = false;
    _clipboard.ObservableFormats.Images = false;
    _clipboard.ObservableFormats.Others = false;
    _clipboard.ClipboardChanged += _clipboard_ClipboardChanged;
    _clipboard.StartMonitoring();
}

private void Options_MonitorClipboardChanged(object sender, EventArgs e)
{
    _clipboard.MonitorClipboard = Options.MonitorClipboard;
}

}`

Willy-Kimura commented 5 years ago

Seems it works fine on my end.

Try comparing yours with the Tests project and see the minor changes you can make. Also, you don't need to use the inherited property InitializeLifetimeService.

Willy-Kimura commented 5 years ago

Fixed the multiple event invocations issue. Will be publishing the next update ASAP.

Willy-Kimura commented 5 years ago

Published v3.3.0 with fix.

satyris commented 4 years ago

Fix works on my side. Thanks!