1

I would like to clear the clipboard, however sometimes this is during a loop and a file might still be in the process of copying to the clipboard so calling Clipboard.Clear() raises an exception.

I made the following function to handle this:

Private Shared Sub ClearClipboard()
    Dim b As Boolean = False
    While b = False
        Try
            Clipboard.Clear()
            b = True
        Catch ex As Exception
        End Try
    End While
End Sub

This works fine on my machine running from Visual Studio, however on the client's machine the unhandled exception message pops up. Why is it not being caught silently there?

Alternatively, if this is not the best way of going about it, how can I check if something is currently being copied to the clipboard and wait until it is finished? In other words is it possible to check if the clipboard is "busy"?

Sparrowhawk
  • 358
  • 1
  • 4
  • 11
  • 1
    Have you tried this solution? https://stackoverflow.com/questions/930219/how-to-handle-blocked-clipboard-and-other-oddities – Neal Jun 08 '17 at 10:13

1 Answers1

1

Thank you Neal!

Looked through that and in the end I can remove the whole loop and Clipboard.SetDataObject("", False, 20, 300) works fine instead of Clipboard.Clear()

Sparrowhawk
  • 358
  • 1
  • 4
  • 11