So, I really came up with my solution. I know I'm a little late, HOWEVER, it seems like this works for me.
// This allows the clipboard to have something copied to it. public static void ClipboardPaste(String pasteString) { // This clears the clipboard Clipboard.Clear(); // This is a "Try" of the statement inside {}, if it fails it goes to "Catch" // If it "Catches" an exception. Then the function will retry itself. try { // This, per some suggestions I found is a half second second wait before another // clipboard clear and before setting the clipboard System.Threading.Thread.Sleep(500); Clipboard.Clear(); // This is, instead of using SetText another method to put something into // the clipboard, it includes a retry/fail set up with a delay // It retries 5 times with 250 milliseconds (0.25 second) between each retry. Clipboard.SetDataObject(pasteString, false, 5, 250); } catch (Exception) { ClipboardPaste(pasteString); } }
This is obviously C #, however these methods are available to all Visual Studios. I obviously created a looping function, and also tried to force it into the clipboard using attempts.
Essentially there is a stream. Suppose you want to put the word Clipboard on the clipboard anywhere in your code (provided that this function is defined).
- Call function ClipboardPaste ("Clipboard");
- Then clear the clipboard
- Then it will "try" to put your string on the clipboard.
- First, it waits for half a second (500 milliseconds).
- Resets clipboard again
- Then it tries to put the string on the clipboard using SetDataObject
- SetDataObject, if it fails, will retry up to 5 times with a delay of 250 milliseconds between each attempt.
- If the initial attempt failed, it detects an exception, abnormal termination, then tries again.
Yes, this has a drawback if you know that your clipboard will always have an exception no matter what (an infinite loop). However, I have not yet encountered an infinite loop with this method. Another drawback is that it can take a couple of seconds (significantly slowing down your applications) before it works, while when you try to freeze your application, as soon as it works, the application will continue to work anyway.
FlyingMongoose Mar 04 2018-12-21T00: 00Z
source share