diff --git a/src/Hangfire.Core/Common/CancellationTokenExtentions.cs b/src/Hangfire.Core/Common/CancellationTokenExtentions.cs
index 854f06079..a2e890f5f 100644
--- a/src/Hangfire.Core/Common/CancellationTokenExtentions.cs
+++ b/src/Hangfire.Core/Common/CancellationTokenExtentions.cs
@@ -28,6 +28,7 @@ public static class CancellationTokenExtentions
/// on cancellation token registration and avoids using the
/// property as it may lead to high CPU issues.
///
+ [Obsolete("CancellationToken.WaitHandle is now preferred, since early days of .NET Core passed. Will be removed in 2.0.0.")]
public static CancellationEvent GetCancellationEvent(this CancellationToken cancellationToken)
{
return new CancellationEvent(cancellationToken);
@@ -56,10 +57,8 @@ public static void WaitOrThrow(this CancellationToken cancellationToken, TimeSpa
///
public static bool Wait(this CancellationToken cancellationToken, TimeSpan timeout)
{
- using var cancellationEvent = GetCancellationEvent(cancellationToken);
-
var stopwatch = Stopwatch.StartNew();
- var waitResult = cancellationEvent.WaitHandle.WaitOne(timeout);
+ var waitResult = cancellationToken.WaitHandle.WaitOne(timeout);
stopwatch.Stop();
var timeoutThreshold = TimeSpan.FromMilliseconds(1000);
@@ -84,6 +83,7 @@ public static bool Wait(this CancellationToken cancellationToken, TimeSpan timeo
return waitResult;
}
+ [Obsolete("CancellationToken.WaitHandle is now preferred, since early days of .NET Core passed. Will be removed in 2.0.0.")]
public sealed class CancellationEvent : IDisposable
{
private static readonly Action