Skip to content

Instantly share code, notes, and snippets.

@i3arnon
Created October 6, 2015 20:52
Show Gist options
  • Save i3arnon/f381c22e2614d97aaca5 to your computer and use it in GitHub Desktop.
Save i3arnon/f381c22e2614d97aaca5 to your computer and use it in GitHub Desktop.
Timer.Change takes a lock on a singleton instance.
internal bool Change(uint dueTime, uint period)
{
bool success;
lock (TimerQueue.Instance)
{
if (m_canceled)
throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_Generic"));
// prevent ThreadAbort while updating state
try { }
finally
{
m_period = period;
if (dueTime == Timeout.UnsignedInfinite)
{
TimerQueue.Instance.DeleteTimer(this);
success = true;
}
else
{
if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.ThreadTransfer))
FrameworkEventSource.Log.ThreadTransferSendObj(this, 1, string.Empty, true);
success = TimerQueue.Instance.UpdateTimer(this, dueTime, period);
}
}
}
return success;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment