Skip to content

Commit 5695157

Browse files
Copilotdanroth27
andcommitted
Add back try/catch logic to memory pool code example
Co-authored-by: danroth27 <1874516+danroth27@users.noreply.github.com>
1 parent 73c5df9 commit 5695157

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

release-notes/10.0/preview/preview6/aspnetcore.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ public class MyBackgroundService : BackgroundService
4848
{
4949
while (!stoppingToken.IsCancellationRequested)
5050
{
51-
// Use memory from the pool
52-
var rented = _memoryPool.Rent(100);
53-
// ... do work ...
54-
rented.Dispose();
55-
await Task.Delay(20, stoppingToken);
51+
try
52+
{
53+
await Task.Delay(20, stoppingToken);
54+
// do work that needs memory
55+
var rented = _memoryPool.Rent(100);
56+
rented.Dispose();
57+
}
58+
catch (OperationCanceledException)
59+
{
60+
return;
61+
}
5662
}
5763
}
5864
}

0 commit comments

Comments
 (0)