That would be good.
Here is my current implementation. With DropBox, I have never seen more than 2 retries needed and 2 is much less common than 1. Its possible that other applications could keep the clipboard open while performing network I/O which could take longer that 1/8 seconds. Some of the search hits for this problem mention Remote Desktop.
Using a uniform delay of 100 ms which is the .Net behaviour doubled the average time taken by Scintilla’s main automated tests when there is a clash. The automated tests are very susceptible to this issue, likely because they perform copies then immediately paste and any clipboard watchers will open the clipboard as soon as they see the clipboard change because of the copy. Application operations and user macros that work through the clipboard will probably see a similar chance of clashes.
// OpenClipboard may fail if another application has opened the clipboard.
// Try up to 8 times, with an initial delay of 1 ms and an exponential back off
// for a maximum total delay of 127 ms (1+2+4+8+16+32+64).
static bool OpenClipboardRetry(HWND hwnd) {
for (int attempt=0; attempt<8; attempt++) {
if (attempt > 0) {
::Sleep(1 << (attempt-1));
}
if (::OpenClipboard(hwnd)) {
if (attempt > 0)
Platform::DebugPrintf("Failed %d times", attempt);
return true;
}
}
return false;
}