.NET Framework - Solid method to deal with clipboard when using Office/VNC/RDP

Asked By Crazy on 28-Mar-12 03:34 AM
Hi guys.

I want to make a simple clipboard manager which strips the formatting
from the text in the clipboard.
I currently have this code:

try
{
Clipboard.SetText(strClipboard);
}
catch
{
}

I have browsed the web for the best solution on this and I cannot find
any better solution than the above, where it catches the exception if
it for some reason fails (because it typically does the job though it
throw an exception).

When I am using VNC, RDP and/or Office applications together, it just
simple does not work very well and it can even throw an error, halting
my application:

************** Exception Text **************
System.Runtime.InteropServices.ExternalException (0x800401D0):
Requested Clipboard operation did not succeed.
at System.Windows.Forms.Clipboard.ThrowIfFailed(Int32 hr)
at System.Windows.Forms.Clipboard.GetDataObject(Int32 retryTimes,
Int32 retryDelay)
at System.Windows.Forms.Clipboard.GetDataObject()
at System.Windows.Forms.Clipboard.ContainsText(TextDataFormat
format)
at System.Windows.Forms.Clipboard.ContainsText()
at ClipMan.Form1.timer1_Tick(Object sender, EventArgs e) in C:
\Visual Studio Projects\ClipMan\ClipMan\Form1.cs:line 113
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
[CUT]

What is the most robust way I can make this so it at least is not
halting when using RDP/VNC/Office?

And is there even a solution for making it work together with those
applications?




Crazy replied to Crazy on 30-Mar-12 03:08 AM
No one has any good suggestions for this one?
Crazy replied to Crazy on 16-Apr-12 02:45 AM
I am supprised that no one has replied to this one yet - either this
is because it is impossible to do or else no one has bothered looking
in to this previously?
Peter Duniho replied to Crazy on 16-Apr-12 02:58 AM
Could be a variety of reasons. But mainly, you did not really post an actual
question with actual code.  it is not like even if someone was interested in
investigating, there is enough information to do anything useful.

I know from past experience that a) being a very old feature of Windows,
the clipboard API has some awkwardness, and b) it does actually work in
general, even when using a remote desktop implementation.

If you are having trouble, it is not surprising, but it does suggest you are
doing something out of the ordinary (e.g. the remote desktop scenario you
seem to be dealing with is relevant).  If you want help (either from this
newsgroup or elsewhere), you will need to provide a solid reproducible
example.  A concise-but-complete code example that reliably reproduces the
problem.

Pete
Crazy replied to Peter Duniho on 16-Apr-12 07:20 AM
al
d in
e
is
the

The problem is exactly that I have not been able to reproduce it. It
just happens from time to time. Sometimes I only need to have 1 open
RDP and copy 1 thing and other times I need to have multiple RDPs and
VNCs open before it crashes. It is not at all solid. And I need a
solid method which takes at least RDP, VNC and Office into
consideration.

I actually did provide the code which is very very simple and this
code should not crash (wrapped in a catch) but it still does.
Peter Duniho replied to Crazy on 16-Apr-12 01:11 PM
www.sscce.org
http://www.yoda.arachsys.com/csharp/complete.html
http://www.yoda.arachsys.com/csharp/incomplete.html

Note that if your problem is not reliably reproducible, then it is even less
likely anyone else would be able to reproduce it, as well as even less
likely that the problem genuinely has anything at all to do with C# or even
.NET (i.e. the kinds of questions that are actually on-topic in this
newsgroup).

You should not be at all surprised that you received no reply to your
question.  In the context of this newsgroup, it is basically just noise,
which most people generally try to ignore.

Pete