Skip to content

Commit 11a06a2

Browse files
committed
fix
1 parent 2bc5fdb commit 11a06a2

File tree

7 files changed

+29
-8
lines changed

7 files changed

+29
-8
lines changed

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ protected async Task Abort()
255255
using var currentCts = cts;
256256
cts = new();
257257

258-
await currentCts.CancelAsync();
258+
await currentCts.TryCancel();
259259
}
260260

261261
public async ValueTask DisposeAsync()
@@ -264,7 +264,7 @@ public async ValueTask DisposeAsync()
264264
{
265265
using var currentCts = cts;
266266
cts = null;
267-
await currentCts.CancelAsync();
267+
await currentCts.TryCancel();
268268
}
269269

270270
await DisposeAsync(true);

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/MainLayout.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private async Task SetCurrentUser(Task<AuthenticationState> task)
143143

144144
using var currentCts = getCurrentUserCts;
145145
getCurrentUserCts = new();
146-
await currentCts.CancelAsync();
146+
await currentCts.TryCancel();
147147

148148
if (authUser.IsAuthenticated() is false)
149149
{
@@ -196,7 +196,7 @@ public async ValueTask DisposeAsync()
196196
{
197197
if (getCurrentUserCts is not null)
198198
{
199-
await getCurrentUserCts.CancelAsync();
199+
await getCurrentUserCts.TryCancel();
200200
getCurrentUserCts.Dispose();
201201
}
202202

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/Management/RolesPage.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private async Task HandleOnSelectRole(BitNavItem? item)
9797
using var currentCts = loadRoleDataCts;
9898
loadRoleDataCts = new();
9999

100-
await currentCts.CancelAsync();
100+
await currentCts.TryCancel();
101101
}
102102

103103
loadRoleDataCts = new();
@@ -398,7 +398,7 @@ protected override async ValueTask DisposeAsync(bool disposing)
398398
{
399399
if (loadRoleDataCts is not null)
400400
{
401-
await loadRoleDataCts.CancelAsync();
401+
await loadRoleDataCts.TryCancel();
402402
loadRoleDataCts.Dispose();
403403
}
404404

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/Management/UsersPage.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private async Task HandleOnSelectUser(BitNavItem? item)
110110
using var currentCts = loadRoleDataCts;
111111
loadRoleDataCts = new();
112112

113-
await currentCts.CancelAsync();
113+
await currentCts.TryCancel();
114114
}
115115

116116
loadRoleDataCts = new();

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async Task ReadIncomingMessages()
4343
await foreach (var incomingMessage in incomingMessages)
4444
{
4545
if (messageSpecificCancellationTokenSrc is not null)
46-
await messageSpecificCancellationTokenSrc.CancelAsync();
46+
await messageSpecificCancellationTokenSrc.TryCancel();
4747

4848
messageSpecificCancellationTokenSrc = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
4949
_ = chatbotService.ProcessNewMessage(
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace System.Threading;
2+
3+
public static class CancellationTokenSourceExtensions
4+
{
5+
/// <summary>
6+
/// Tries to cancel the <see cref="CancellationTokenSource"/> without throwing an exception if it has already been disposed.
7+
/// </summary>
8+
public static async Task<bool> TryCancel(this CancellationTokenSource source)
9+
{
10+
try
11+
{
12+
await source.CancelAsync();
13+
return true;
14+
}
15+
catch (ObjectDisposedException)
16+
{
17+
return false;
18+
}
19+
}
20+
}

src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/appsettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"Comment2": "Integrates Sentry across both backend and frontend projects",
3737
"Dsn": "",
3838
"SendDefaultPii": true,
39+
"TracesSampleRate": 1.0,
3940
"EnableScopeSync": true,
4041
"LogLevel": {
4142
"Default": "Warning",

0 commit comments

Comments
 (0)