예제 #1
0
        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);
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        public void Dispose()
        {
            if (MyState == State.Disposed)
            {
                return;
            }
            MyState = State.Disposed;

            PumpTimer.CancelDoLater(HeartbeatCookie);

            try
            {
                OnDispose();
            }
            catch (Exception)
            {
            }

            CleanupRabbit();
        }