private void OnRegisterServer(object state)
{
try
{
lock (m_registrationLock)
{
// halt any outstanding timer.
if (m_registrationTimer != null)
{
m_registrationTimer.Dispose();
m_registrationTimer = null;
}
}
if (RegisterWithDiscoveryServer())
{
// schedule next registration.
lock (m_registrationLock)
{
if (m_maxRegistrationInterval > 0)
{
m_registrationTimer = new Timer(
OnRegisterServer,
this,
m_maxRegistrationInterval,
Timeout.Infinite);
m_lastRegistrationInterval = m_minRegistrationInterval;
Utils.Trace("Register server succeeded. Registering again in {0} ms", m_maxRegistrationInterval);
}
}
}
else
{
lock (m_registrationLock)
{
if (m_registrationTimer == null)
{
// calculate next registration attempt.
m_lastRegistrationInterval *= 2;
if (m_lastRegistrationInterval > m_maxRegistrationInterval)
{
m_lastRegistrationInterval = m_maxRegistrationInterval;
}
Utils.Trace("Register server failed. Trying again in {0} ms", m_lastRegistrationInterval);
// create timer.
m_registrationTimer = new Timer(OnRegisterServer, this, m_lastRegistrationInterval, Timeout.Infinite);
}
}
}
}
catch (Exception e)
{
Utils.Trace(e, "Unexpected exception handling registration timer.");
}
}
#endregion