public void CancelAfter(int millisecondsDelay) { if (millisecondsDelay < -1) { throw new ArgumentOutOfRangeException("millisecondsDelay"); } CheckDisposed(); if (canceled || millisecondsDelay == Timeout.Infinite) { return; } if (timer == null) { // Have to be carefull not to create secondary background timer var t = new Timer(timer_callback, this, Timeout.Infinite, Timeout.Infinite); if (AotInterlocked.CompareExchange(ref timer, t, null) != null) { t.Dispose(); } } timer.Change(millisecondsDelay, Timeout.Infinite); }
void UnregisterLinkedTokens() { var registrations = AotInterlocked.Exchange(ref linkedTokens, null); if (registrations == null) { return; } foreach (var linked in registrations) { linked.Dispose(); } }