public static void SetText(string text) { Exception exception = null; for (var i = 0; i < 5; i++) { try { Clipboard.SetText(text); return; } catch (Exception e) { Thread.Sleep(10); exception = e; } } NonfatalError.Notify("Can’t copy text", "No access to clipboard.", exception); }
/*public static bool SetText(string text) { * if (!OpenClipboard(IntPtr.Zero)) { * return false; * } * * var global = Marshal.StringToHGlobalUni(text); * SetClipboardData(CF_UNICODETEXT, global); * CloseClipboard(); * return true; * }*/ public static void SetText(string text) { ActionExtension.InvokeInMainThreadAsync(() => { Exception exception = null; for (var i = 0; i < 5; i++) { try { Clipboard.SetText(text); return; } catch (Exception e) { Thread.Sleep(10); exception = e; } } NonfatalError.NotifyBackground("Can’t copy text", "No access to clipboard.", exception); }); }
protected override async Task ExecuteInner() { try { using (var waiting = new WaitingDialog()) { waiting.Report("Solving the issue…"); await _execute(waiting.CancellationToken); } } catch (TaskCanceledException) { return; } catch (Exception e) { NonfatalError.Notify("Can’t solve the issue", e); return; } Solved = true; if (_entry != null) { NonfatalError.Instance.Errors.Remove(_entry); } }