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 SetEventCallback = SetEvent; diff --git a/src/Hangfire.Core/Processing/TaskExtensions.cs b/src/Hangfire.Core/Processing/TaskExtensions.cs index 683844a8c..b9b46d6c0 100644 --- a/src/Hangfire.Core/Processing/TaskExtensions.cs +++ b/src/Hangfire.Core/Processing/TaskExtensions.cs @@ -36,9 +36,7 @@ public static bool WaitOne([NotNull] this WaitHandle waitHandle, TimeSpan timeou token.ThrowIfCancellationRequested(); - using var ev = token.GetCancellationEvent(); - - var waitHandles = new[] { waitHandle, ev.WaitHandle }; + var waitHandles = new[] { waitHandle, token.WaitHandle }; var stopwatch = Stopwatch.StartNew(); var waitResult = WaitHandle.WaitAny(waitHandles, timeout); diff --git a/src/Hangfire.Core/Server/CoreBackgroundJobPerformer.cs b/src/Hangfire.Core/Server/CoreBackgroundJobPerformer.cs index 35c99dd8f..fbaaf5023 100644 --- a/src/Hangfire.Core/Server/CoreBackgroundJobPerformer.cs +++ b/src/Hangfire.Core/Server/CoreBackgroundJobPerformer.cs @@ -182,7 +182,6 @@ private static object InvokeOnTaskPump(PerformContext context, Tuple