Cancel CTS immediately if delay is zero. (#18098)
authorElliot Prior <1709938+Quogu@users.noreply.github.com>
Fri, 25 Jan 2019 13:59:30 +0000 (13:59 +0000)
committerStephen Toub <stoub@microsoft.com>
Fri, 25 Jan 2019 13:59:30 +0000 (08:59 -0500)
commitdcdfeea0b85b09e0f066fdfd05f5fef289977ab9
treeae2e3910537fe64e3123a8bb028b6677ed7fffda
parentcdd6e3315ff125aabc34378d5547f68df89c05c2
Cancel CTS immediately if delay is zero. (#18098)

The intended behaviour on specifying a delay of zero is that the CancellationTokenSource is cancelled immediately - before this change, it would depend on the scheduling of the timer callback which could lead to seeing a non-cancelled token. Now, it marks itself as cancelled immediately, without invoking any callbacks (as this method is called only from within the constructor of the object, before any callbacks could have been registered.
src/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs