Skip to content

Commit

Permalink
replace TimeSpan.FromMilliseconds(-1) with Timeout.InfiniteTimeSpan
Browse files Browse the repository at this point in the history
  • Loading branch information
afifi-ins authored and mconnew committed Aug 7, 2024
1 parent af275d1 commit c7b4036
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void CancelTimer()
{
if (_idleTimer != null)
{
_idleTimer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
_idleTimer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
}
}

Expand All @@ -180,11 +180,11 @@ private void StartTimerIfNecessary()
s_onIdle = new Action<object>(OnIdle);
}

_idleTimer = new Timer(new TimerCallback(new Action<object>(s_onIdle)), this, _idleTimeout, TimeSpan.FromMilliseconds(-1));
_idleTimer = new Timer(new TimerCallback(new Action<object>(s_onIdle)), this, _idleTimeout, Timeout.InfiniteTimeSpan);
}
else
{
_idleTimer.Change(_idleTimeout, TimeSpan.FromMilliseconds(-1));
_idleTimer.Change(_idleTimeout, Timeout.InfiniteTimeSpan);
}
}
}
Expand Down Expand Up @@ -267,7 +267,7 @@ public void Prune(List<TItem> itemsToClose, bool calledFromTimer)

if (calledFromTimer && setTimer)
{
_idleTimer.Change(_idleTimeout, TimeSpan.FromMilliseconds(-1));
_idleTimer.Change(_idleTimeout, Timeout.InfiniteTimeSpan);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ public AsyncQueueReader(InputQueue<T> inputQueue, TimeSpan timeout, AsyncCallbac
_inputQueue = inputQueue;
if (timeout != TimeSpan.MaxValue)
{
_timer = new Timer(new TimerCallback(s_timerCallback), this, timeout, TimeSpan.FromMilliseconds(-1));
_timer = new Timer(new TimerCallback(s_timerCallback), this, timeout, Timeout.InfiniteTimeSpan);
}
}

Expand All @@ -932,7 +932,7 @@ public void Set(Item item)
_item = item.Value;
if (_timer != null)
{
_timer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
_timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
}
Complete(false, item.Exception);
}
Expand All @@ -958,7 +958,7 @@ public AsyncQueueWaiter(TimeSpan timeout, AsyncCallback callback, object state)
{
if (timeout != TimeSpan.MaxValue)
{
_timer = new Timer(new TimerCallback(s_timerCallback), this, timeout, TimeSpan.FromMilliseconds(-1));
_timer = new Timer(new TimerCallback(s_timerCallback), this, timeout, Timeout.InfiniteTimeSpan);
}
}

Expand All @@ -976,7 +976,7 @@ public void Set(bool itemAvailable)

lock (ThisLock)
{
timely = (_timer == null) || _timer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
timely = (_timer == null) || _timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
_itemAvailable = itemAvailable;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2339,7 +2339,7 @@ internal AsyncWaiter(CallOnceManager manager, TimeSpan timeout,

if (timeout != TimeSpan.MaxValue)
{
_timer = new Timer(s_timeoutCallback, this, timeout, TimeSpan.FromMilliseconds(-1));
_timer = new Timer(s_timeoutCallback, this, timeout, Timeout.InfiniteTimeSpan);
}
}

Expand All @@ -2350,7 +2350,7 @@ internal static void End(IAsyncResult result)

void IWaiter.Signal()
{
if ((_timer == null) || _timer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1)))
if ((_timer == null) || _timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan))
{
Complete(false);
_manager._channel.Closed -= OnClosed;
Expand All @@ -2363,7 +2363,7 @@ void IWaiter.Signal()

private void OnClosed(object sender, EventArgs e)
{
if ((_timer == null) || _timer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1)))
if ((_timer == null) || _timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan))
{
Complete(false, _manager._channel.CreateClosedException());
}
Expand Down Expand Up @@ -2406,7 +2406,7 @@ internal class SessionIdleManager
private SessionIdleManager(IChannelBinder binder, TimeSpan idle)
{
_binder = binder;
_timer = new Timer(new TimerCallback(GetTimerCallback()), this, idle, TimeSpan.FromMilliseconds(-1));
_timer = new Timer(new TimerCallback(GetTimerCallback()), this, idle, Timeout.InfiniteTimeSpan);
_idleTicks = Ticks.FromTimeSpan(idle);
_thisLock = new Object();
}
Expand Down Expand Up @@ -2439,7 +2439,7 @@ internal void CancelTimer()
lock (_thisLock)
{
_isTimerCancelled = true;
_timer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
_timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
}
}

Expand Down Expand Up @@ -2508,7 +2508,7 @@ private void TimerCallback()
{
if (!_isTimerCancelled && _binder.Channel.State != CommunicationState.Faulted && _binder.Channel.State != CommunicationState.Closed)
{
_timer.Change(Ticks.ToTimeSpan(abortTime - ticksNow), TimeSpan.FromMilliseconds(-1));
_timer.Change(Ticks.ToTimeSpan(abortTime - ticksNow), Timeout.InfiniteTimeSpan);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ internal AsyncDuplexRequest(Message message, DuplexChannelBinder parent, TimeSpa

if (timeout != TimeSpan.MaxValue)
{
_timer = new Timer(new TimerCallback(AsyncDuplexRequest.s_timerCallback), this, timeout, TimeSpan.FromMilliseconds(-1));
_timer = new Timer(new TimerCallback(AsyncDuplexRequest.s_timerCallback), this, timeout, Timeout.InfiniteTimeSpan);
}
if (DiagnosticUtility.ShouldUseActivity)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal void AfterReply(ref MessageRpc rpc)
{
if (rpc.Operation.IsTerminating && rpc.Channel.HasSession)
{
var timer = new Timer(s_abortChannelTimerCallback, rpc.Channel.Binder.Channel, rpc.Channel.CloseTimeout, TimeSpan.FromMilliseconds(-1));
var timer = new Timer(s_abortChannelTimerCallback, rpc.Channel.Binder.Channel, rpc.Channel.CloseTimeout, Timeout.InfiniteTimeSpan);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void CancelTimerIfNeeded()
{
if (Count == 0 && _purgingTimer != null)
{
_purgingTimer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
_purgingTimer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
_purgingTimer.Dispose();
_purgingTimer = null;
}
Expand All @@ -90,7 +90,7 @@ private void StartTimerIfNeeded()
}
if (_purgingTimer == null)
{
_purgingTimer = new Timer(new TimerCallback(PurgeCallback), this, _purgeInterval, TimeSpan.FromMilliseconds(-1));
_purgingTimer = new Timer(new TimerCallback(PurgeCallback), this, _purgeInterval, Timeout.InfiniteTimeSpan);
}
}

Expand Down Expand Up @@ -420,7 +420,7 @@ private static void PurgeCallbackStatic(object state)
self.PurgeStaleItems();
if (self.Count > 0 && self._purgingTimer != null)
{
self._purgingTimer.Change(self._purgeInterval, TimeSpan.FromMilliseconds(-1));
self._purgingTimer.Change(self._purgeInterval, Timeout.InfiniteTimeSpan);
}
}
finally
Expand Down

0 comments on commit c7b4036

Please sign in to comment.