コード例 #1
0
ファイル: ClientSocketBase.cs プロジェクト: Akrotiri/twino
        /// <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);
        }
コード例 #2
0
ファイル: ClientSocketBase.cs プロジェクト: Akrotiri/twino
        /// <summary>
        /// Destroyes ping timer and releases all sources
        /// </summary>
        private void DestroyPingTimer()
        {
            if (_pingTimer == null)
            {
                return;
            }

            _pingTimer.Stop();
            _pingTimer = null;
        }