Opc.Ua.Client.Session.StartKeepAliveTimer C# (CSharp) Method

StartKeepAliveTimer() private method

Starts a timer to check that the connection to the server is still available.
private StartKeepAliveTimer ( ) : void
return void
        private void StartKeepAliveTimer()
        {
            int keepAliveInterval = m_keepAliveInterval;

            lock (m_eventLock)
            {
                m_serverState = ServerState.Unknown;
                m_lastKeepAliveTime = DateTime.UtcNow;
            }
            
            ReadValueIdCollection nodesToRead = new ReadValueIdCollection();

            // read the server state.
            ReadValueId serverState = new ReadValueId();

            serverState.NodeId       = Variables.Server_ServerStatus_State;
            serverState.AttributeId  = Attributes.Value;
            serverState.DataEncoding = null;
            serverState.IndexRange   = null;

            nodesToRead.Add(serverState);

            // restart the publish timer.
            lock (SyncRoot)
            {
                if (m_keepAliveTimer != null)
                {
                    m_keepAliveTimer.Dispose();
                    m_keepAliveTimer = null;
                }

                // start timer.
                m_keepAliveTimer = new Timer(OnKeepAlive, nodesToRead, keepAliveInterval, keepAliveInterval);
            }

            // send initial keep alive.
            OnKeepAlive(nodesToRead);
        }