Skip to content

Commit 233cf2c

Browse files
CopilotYBTopaz8
andcommitted
Dispose existing CancellationTokenSource before creating new one
Prevents potential resource leaks if InitializeAllVMCoreComponentsAsync is called multiple times. Co-authored-by: YBTopaz8 <41630728+YBTopaz8@users.noreply.github.com>
1 parent e04b537 commit 233cf2c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Dimmer/Dimmer/ViewModel/BaseViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,11 @@ await lastFMRealm.WriteAsync(() =>
680680
$"{DateTime.Now}: Finished InitializeAllVMCoreComponentsAsync in {duration.TotalSeconds} seconds.");
681681

682682
// Initialize background caching with proper error handling and cancellation support
683+
// Dispose existing token if it exists (e.g., if this method is called multiple times)
684+
_backgroundCachingCts?.Cancel();
685+
_backgroundCachingCts?.Dispose();
683686
_backgroundCachingCts = new CancellationTokenSource();
687+
684688
_ = Task.Run(async () =>
685689
{
686690
try

0 commit comments

Comments
 (0)