Clipboard Problem

lothos12345

Junior Contributor
Joined
May 2, 2002
Messages
294
Location
Texas
i am using the clipboard to copy and paste text on the textcontrol. Which seems to work fine on some computers well as others it throws me the following error.

Cannot read from or write to the clipboard (01-1603)

throwkernelerror


One thought I had was after each paste of the text or before I set the dataobject in the clipboard, i call the garbage collector. My thought is that something the computer is doing is locking the clipboard and calling the garbage collection will free the clipboard up.
 
This begs the question: why are you calling the garbage collector. As long as you know that this is supposed to be automated and understand the implications of explicitly invoking a garbage collection (under most circumstances it will actually cause the garbage collector to perform less efficiently), or in other words, if you really know what you are doing, then do what you will, but I'd recommend you avoid calling the garbage collector explicitly.

If you must call the garbage collector, I don't know the finer details but it could be that something relating to the ClipBoard class is pinned or being moved or something. I don't know if code is allowed to be executed during a collection. If that is the case, you might want to try to do an Application.DoEvents after the call to GC.Collect to allow the GC thread to finish up. Otherwise, I don't know what to tell you.
 
I am not calling the garbage collector as of yet, it was just an ideal I had, I thought that something was still using the clipboard and the program was not giving the clipboard enough time to do what it needed to do. Garbage collection i would force it to clean itself up. Not sure what else to try. Some computers I have no problem to use the clipboard for copying and pasting. While still others I get the error. Any thoughts?
 
Yes all the systems are running the exact same version of the Windows and the exact same version of the application and all the pc's are the same as far as hardware and brand.
 
My bad. I guess I should pay attention when I read a post. I thought you said that you were forcing garbage collections. But have you tried calling Application.DoEvents to let other threads finish what they are doing before accessing the clipboard? I don't see why it should be necessary, but who knows?
 
Back
Top