Exemplo n.º 1
0
        /// <summary>
        /// Creates new ping timer
        /// </summary>
        private void CreatePingTimer()
        {
            if (_pingTimer != null)
            {
                DestroyPingTimer();
            }

            if (PingInterval == TimeSpan.Zero)
            {
                return;
            }

            _pingTimer = new ThreadTimer(() =>
            {
                if (!IsConnected)
                {
                    DestroyPingTimer();
                    return;
                }

                if (DateTime.UtcNow - LastAliveDate > PingInterval)
                {
                    Ping();
                }
            }, TimeSpan.FromMilliseconds(5000));

            _pingTimer.Start(ThreadPriority.Lowest);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Destroyes ping timer and releases all sources
        /// </summary>
        private void DestroyPingTimer()
        {
            if (_pingTimer == null)
            {
                return;
            }

            _pingTimer.Stop();
            _pingTimer = null;
        }