Discussion:
Clipboard.GetText & error 521: Cannot open Clipboard
(too old to reply)
Jack
2004-10-10 04:48:29 UTC
Permalink
Very often, when repeatedly calling Clipboard.GetText I have error 521:
Cannot open Clipboard.
What can cause that and how to prevent it?
Bob O`Bob
2004-10-10 05:32:51 UTC
Permalink
Post by Jack
Cannot open Clipboard.
What can cause that and how to prevent it?
The previous operation hasn't completed?


A DoEvents call might possibly help, but it might take more than just that.

If the code in which you're trying to do clipboard operations is in
(or called by) event code that was itself triggered by a clipboard
operation, then you might need to do some redesign.

I've got a utility I use occasionally, which does rather a lot of processing
from within the change event of a textbox. If I paste into that textbox, and
quickly switch to another application where I attempt to do a copy, sometimes
I get errors (in the other app!) due to blocking caused by my utility.
One of these days I'll rewrite it - probably have the change event set a very
short timer, and move the heavy processing into the timer event.



Bob
--
Tom Esh
2004-10-10 12:08:01 UTC
Permalink
Post by Jack
Cannot open Clipboard.
What can cause that and how to prevent it?
It's somewhat rare, but that can happen when another app is using the
clipboard or just fails to release clipboard ownership. As Bob
suggested, about the only thing you can in that case is retry. Ideally
you should use error handling for all clipboard ops and probably (much
as I hate msg boxes) inform the user what's happening and give them a
Retry/Cancel choice. It's one of those things that often gets
overlooked ...'till it bites <g>


-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
Jack
2004-10-10 15:27:48 UTC
Permalink
What I do is just call Clipboard.GetText when get notification about
clipboard change.
The change in clipboard (the effect of user puting different data on
clipboard) is not more often then 2-3 minutes.
I noticed when I will wait for 5-6 minutes then there is not error; probably
Windows release clipboard by default.
I noticed also that calling Clipboard.GetText twice in succession will
create error when calling for the first time but second time calling will
not create error any more.
Jack
Post by Tom Esh
Post by Jack
Cannot open Clipboard.
What can cause that and how to prevent it?
It's somewhat rare, but that can happen when another app is using the
clipboard or just fails to release clipboard ownership. As Bob
suggested, about the only thing you can in that case is retry. Ideally
you should use error handling for all clipboard ops and probably (much
as I hate msg boxes) inform the user what's happening and give them a
Retry/Cancel choice. It's one of those things that often gets
overlooked ...'till it bites <g>
-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
Continue reading on narkive:
Loading...