Hi Hong,
This error (0x800401D0
) indicates that the clipboard is temporarily unavailable — usually because another process or thread is accessing it at the same time. Since the clipboard is a shared system resource, this can cause occasional race conditions.
As David Lowndes mentioned in comment, there is a common workaround which is to add a retry loop with a short delay when calling Clipboard.SetContent
, you can apply that solution like this:
var dp = new DataPackage();
dp.SetText(sText);
int retries = 3; // Edit number of retries if needed
while (retries-- > 0)
{
try
{
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Clipboard.SetContent(dp);
});
break; // Success
}
catch (Exception ex) when ((uint)ex.HResult == 0x800401D0)
{
// Clipboard is busy, wait and retry
await Task.Delay(100);
}
}
If you have any question, feel free to ask! Thank you!