public static bool WaitFor(Func <bool> pred, int timeoutMs = 0, int testIntervalMs = 10, bool withDoEvent = false) { if (testIntervalMs < 1) { testIntervalMs = 10; } DateTime now = DateTime.Now; var isTimeout = false; while (true) { if (pred()) { break; } if (timeoutMs > 0 && now.xIsTimeElapseMoreThanMs(timeoutMs)) { isTimeout = true; break; } if (withDoEvent) { DispatcherEx.DoEvents(); } Thread.Sleep(testIntervalMs); } return(isTimeout); }
private bool SendPlainImage(BitmapImage img) { bool isok = false; DispatcherEx.xInvoke(() => { HwndInfo hwndInfo = this.GetActivedEditorHwnd(); if (hwndInfo.Handle > 0) { this.FocusEditor(true); WinApi.Editor.MoveCaretToEnding(hwndInfo); var dict = ClipboardEx.Backup(); Clipboard.Clear(); Clipboard.SetImage(img); string text = this.GetPlainTextUnCached(); WinApi.PressCtrlV(); DateTime now = DateTime.Now; while ((DateTime.Now - now).TotalSeconds < 2.0) { string newText = this.GetPlainTextUnCached(); if (newText != text) { isok = true; } DispatcherEx.DoEvents(); } Util.WriteTimeElapsed(now, "等待时间"); ClipboardEx.Restore(dict); return; } }); return(isok); }
public static void SleepWithDoEvent(int ms) { Util.Assert(ms > 0); int millisecondsTimeout = Math.Min(30, ms); DateTime now = DateTime.Now; do { Thread.Sleep(millisecondsTimeout); DispatcherEx.DoEvents(); }while ((DateTime.Now - now).TotalMilliseconds < (double)ms); }
public void BringTop() { try { if (IsLoaded) { Topmost = true; DispatcherEx.DoEvents(); Topmost = false; } } catch (Exception e) { Log.Exception(e); } }
public void BringTop() { WinApi.TopMost(this._hwnd); DispatcherEx.DoEvents(); WinApi.CancelTopMost(this._hwnd); }