public override void StartTimer(WebSocketBase webSocket)
{
Debug.Assert(webSocket != null, "'webSocket' MUST NOT be NULL.");
Debug.Assert(webSocket._keepAliveTracker != null,
"'webSocket._KeepAliveTracker' MUST NOT be NULL at this point.");
int keepAliveIntervalMilliseconds = (int)_keepAliveInterval.TotalMilliseconds;
Debug.Assert(keepAliveIntervalMilliseconds > 0, "'keepAliveIntervalMilliseconds' MUST be POSITIVE.");
// The correct pattern is to first initialize the Timer object, assign it to the member variable
// and only afterwards enable the Timer. This is required because the constructor, together with
// the assignment are not guaranteed to be an atomic operation, which creates a race between the
// assignment and the Timer callback.
_keepAliveTimer = new Timer(s_KeepAliveTimerElapsedCallback, webSocket, Timeout.Infinite,
Timeout.Infinite);
_keepAliveTimer.Change(keepAliveIntervalMilliseconds, Timeout.Infinite);
}