Opc.Ua.Com.Server.ComProxy.OnCreateSession C# (CSharp) Method

OnCreateSession() private method

Creates a session with the server.
private OnCreateSession ( object state ) : void
state object The state.
return void
        private async void OnCreateSession(object state)
        {
            // check if nothing to do.
            lock (m_lock)
            {
                if (!m_running || m_session != null)
                {
                    return;
                }

                // stop the reconnect timer.
                if (m_reconnectTimer != null)
                {
                    m_reconnectTimer.Dispose();
                    m_reconnectTimer = null;
                }
            }

            // create the session.
            try
            {
                Session session = await Connect(m_clsid);
                session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive);

                lock (m_lock)
                {
                    // discard unneeded session.
                    if (m_session != null)
                    {
                        session.Dispose();
                        return;
                    }

                    // update the session.
                    m_session = session;
                }

                OnSessionCreated();
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Could not create a Session with the UA Server.");

                // schedule a reconnect.
                lock (m_lock)
                {
                    m_reconnectTimer = new Timer(OnCreateSession, null, 20000, Timeout.Infinite);
                    Utils.Trace("Calling OnCreateSession in 20000ms.");
                    OnReconnectInProgress(20);
                }
            }
        }