Skip to content

Commit 00d9488

Browse files
Permit repeating WaitHandle of infinite timeout (#72267)
* Permit repeating WaitHandle of infinite timeout * Add test for repeating waithandle with infinite timeout
1 parent f40c340 commit 00d9488

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,10 @@ private void QueueWaitCompletion(RegisteredWaitHandle registeredHandle, bool tim
373373
// If the handle is a repeating handle, set up the next call. Otherwise, remove it from the wait thread.
374374
if (registeredHandle.Repeating)
375375
{
376-
registeredHandle.RestartTimeout();
376+
if (!registeredHandle.IsInfiniteTimeout)
377+
{
378+
registeredHandle.RestartTimeout();
379+
}
377380
}
378381
else
379382
{

src/libraries/System.Threading.ThreadPool/tests/RegisteredWaitTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ public static void QueueRegisterPositiveAndFlowTest()
126126
false);
127127
waitForBackgroundWork(true);
128128
Assert.Equal(0, backgroundAsyncLocalValue);
129+
130+
// Validate a repeating waithandle with infinite timeout.
131+
registeredWaitHandle =
132+
ThreadPool.UnsafeRegisterWaitForSingleObject(
133+
registerWaitEvent,
134+
(state, timedOut) =>
135+
{
136+
commonBackgroundTest(true, () =>
137+
{
138+
Assert.Same(obj, state);
139+
Assert.False(timedOut);
140+
});
141+
},
142+
obj,
143+
-1, // Infinite
144+
false); // Execute once
145+
waitForBackgroundWork(true);
146+
Assert.Equal(0, backgroundAsyncLocalValue);
129147
}
130148

131149
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]

0 commit comments

Comments
 (0)