diff --git a/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunner.cs b/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunner.cs index ae72533ef4c4..fb043477db64 100644 --- a/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunner.cs +++ b/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexRunner.cs @@ -206,15 +206,16 @@ protected void CheckTimeout() if (_ignoreTimeout) return; - if (--_timeoutChecksToSkip != 0) - return; - - _timeoutChecksToSkip = TimeoutCheckFrequency; DoCheckTimeout(); } private void DoCheckTimeout() { + if (--_timeoutChecksToSkip != 0) + return; + + _timeoutChecksToSkip = TimeoutCheckFrequency; + // Note that both, Environment.TickCount and timeoutOccursAt are ints and can overflow and become negative. // See the comment in StartTimeoutWatch().