Skip to content

Commit 569dc2f

Browse files
authored
Use the NonCapturingTimer helper (#25183)
* Use the NonCapturingTimer helper * Formatting...
1 parent 31b9499 commit 569dc2f

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

src/SignalR/server/StackExchangeRedis/src/Internal/AckHandler.cs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Concurrent;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.Extensions.Internal;
89

910
namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Internal
1011
{
@@ -19,26 +20,7 @@ internal class AckHandler : IDisposable
1920

2021
public AckHandler()
2122
{
22-
// Don't capture the current ExecutionContext and its AsyncLocals onto the timer
23-
bool restoreFlow = false;
24-
try
25-
{
26-
if (!ExecutionContext.IsFlowSuppressed())
27-
{
28-
ExecutionContext.SuppressFlow();
29-
restoreFlow = true;
30-
}
31-
32-
_timer = new Timer(state => ((AckHandler)state).CheckAcks(), state: this, dueTime: _ackInterval, period: _ackInterval);
33-
}
34-
finally
35-
{
36-
// Restore the current ExecutionContext
37-
if (restoreFlow)
38-
{
39-
ExecutionContext.RestoreFlow();
40-
}
41-
}
23+
_timer = NonCapturingTimer.Create(state => ((AckHandler)state).CheckAcks(), state: this, dueTime: _ackInterval, period: _ackInterval);
4224
}
4325

4426
public Task CreateAck(int id)

src/SignalR/server/StackExchangeRedis/src/Microsoft.AspNetCore.SignalR.StackExchangeRedis.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>Provides scale-out support for ASP.NET Core SignalR using a Redis server and the StackExchange.Redis client.</Description>
@@ -8,6 +8,7 @@
88
<ItemGroup>
99
<Compile Include="$(SignalRSharedSourceRoot)SystemTextJsonExtensions.cs" Link="Internal\SystemTextJsonExtensions.cs" />
1010
<Compile Include="$(SignalRSharedSourceRoot)MemoryBufferWriter.cs" Link="Internal\MemoryBufferWriter.cs" />
11+
<Compile Include="$(SharedSourceRoot)NonCapturingTimer\*.cs" />
1112
</ItemGroup>
1213

1314
<ItemGroup>

0 commit comments

Comments
 (0)