Opc.Ua.Client.SessionReconnectHandler.DoReconnect C# (CSharp) Method

DoReconnect() private method

Reconnects to the server.
private DoReconnect ( ) : bool
return bool
        private bool DoReconnect()
        {
            // try a reconnect.
            if (!m_reconnectFailed)
            {
                try
                {
                    m_session.Reconnect();

                    // monitored items should start updating on their own.
                    return true;
                }
                catch (Exception exception)
                {
                    // recreate the session if it has been closed.
                    ServiceResultException sre = exception as ServiceResultException;

                    // check if the server endpoint could not be reached.
                    if ((sre != null && (sre.StatusCode == StatusCodes.BadTcpInternalError || sre.StatusCode == StatusCodes.BadCommunicationError)) ||
                        exception is System.ServiceModel.EndpointNotFoundException)
                    {
                        // check if reconnecting is still an option.
                        if (m_session.LastKeepAliveTime.AddMilliseconds(m_session.SessionTimeout) > DateTime.UtcNow)
                        {
                            Utils.Trace("Calling OnReconnectSession in {0} ms.", m_reconnectPeriod);

                            return false;
                        }
                    }

                    m_reconnectFailed = true;
                }
            }

            // re-create the session.
            try
            {
                Session session = Session.Recreate(m_session);
                m_session.Close();
                m_session = session;
                return true;
            }
            catch (Exception exception)
            {
                Utils.Trace("Could not reconnect the Session. {0}", exception.Message);
                return false;
            }
        }
        #endregion