static bool WaitInternal(int?msTimeout, Func <bool> condition) { bool timedOut = false; Debug.Assert(SynchronizationContext.Current is DispatcherSynchronizationContext); DispatcherFrame frame = new DispatcherFrame(); DispatcherHookEventHandler onOperationCompleted = null; Action popFrame = () => { frame.Continue = false; Dispatcher.CurrentDispatcher.Hooks.OperationCompleted -= onOperationCompleted; }; onOperationCompleted = (s, ea) => { if (condition()) { popFrame(); } }; Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { Dispatcher.CurrentDispatcher.Hooks.OperationCompleted += onOperationCompleted; })); if (msTimeout != null) { PumpTimer.DoLater(msTimeout.Value, () => { timedOut = true; popFrame(); }); } Dispatcher.PushFrame(frame); return(!timedOut); }
void Heartbeat() { if (MyState == State.Disposed) { return; } HeartbeatCookie = PumpTimer.DoLater(1000, Heartbeat); if (Connection == null || !Connection.IsOpen) { MyState = State.Connecting; SyncContext.Current.Post(() => IsConnectedChanged.Fire(false)); TryToConnect(); } }
public void Dispose() { if (MyState == State.Disposed) { return; } MyState = State.Disposed; PumpTimer.CancelDoLater(HeartbeatCookie); try { OnDispose(); } catch (Exception) { } CleanupRabbit(); }