Esempio n. 1
0
        public void InvalidOperationTests()
        {
            WatchdogTimer uut = new WatchdogTimer(int.MaxValue, "InvalidOperationTests");

            bool started = false;
            bool stopped = false;
            bool reset   = false;

            uut.OnStarted += () => { started = true; };
            uut.OnStopped += () => { stopped = true; };
            uut.OnReset   += () => { reset = true; };

            Assert.Throws <InvalidOperationException>(() => uut.Stop());  // Can't stop if its not started.
            Assert.Throws <InvalidOperationException>(() => uut.Reset());

            // Ensure events didn't fire.
            Assert.IsFalse(started);
            Assert.IsFalse(stopped);
            Assert.IsFalse(reset);

            // Call Start
            uut.Start();
            Assert.IsTrue(started);

            started = false;
            // Calling start again should get an InvalidOperationException
            Assert.Throws <InvalidOperationException>(() => uut.Start());
            Assert.IsFalse(started);
            Assert.IsFalse(stopped);
            Assert.IsFalse(reset);

            uut.Reset();
            Assert.IsFalse(started);
            Assert.IsFalse(stopped);
            Assert.IsTrue(reset);
            reset = false;

            uut.Stop();
            Assert.IsFalse(started);
            Assert.IsTrue(stopped);
            Assert.IsFalse(reset);
            stopped = false;

            uut.Dispose();

            // Should get ObjectDisposedExceptions
            Assert.Throws <ObjectDisposedException>(() => uut.Start());
            Assert.Throws <ObjectDisposedException>(() => uut.Stop());
            Assert.Throws <ObjectDisposedException>(() => uut.Reset());

            Assert.IsFalse(started);
            Assert.IsFalse(stopped);
            Assert.IsFalse(reset);

            // Nothing bad should happen if we call Dispose again
            uut.Dispose();
        }
Esempio n. 2
0
        /// <summary>
        ///     Releases the managed and unmanaged resources used by the <see cref="Connection"/>.
        /// </summary>
        /// <param name="disposing">A value indicating whether the object is in the process of disposing.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!Disposed)
            {
                if (disposing)
                {
                    Disconnect("Connection is being disposed", new ObjectDisposedException(GetType().Name));
                    InactivityTimer?.Dispose();
                    WatchdogTimer?.Dispose();
                    Stream?.Dispose();
                    TcpClient?.Dispose();
                }

                Disposed = true;
            }
        }
Esempio n. 3
0
        private void ClosedEventHandler(object sender, EventArgs e)
        {
            InputManager.Current.PreProcessInput -= GlobalClickEventHandler;
            if (_sourceWindow != null)
            {
                _sourceWindow.RemoveHook(WndProc);
            }

            if (_emergencyTimer != null)
            {
                _emergencyTimer.Stop();
                _emergencyTimer.Dispose();
            }

            if (_timeUpdateTimer != null)
            {
                _timeUpdateTimer.Stop();
            }
        }
Esempio n. 4
0
        public void StartDisposeTest()
        {
            WatchdogTimer uut = new WatchdogTimer(1000, "StartDisposeTest");

            uut.Dispose();
        }