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;
}
}
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);
}
}
}