Browse Source

Add more dispose safety checks

pull/109/head
Ionite 1 year ago
parent
commit
6673270b13
No known key found for this signature in database
  1. 3
      StabilityMatrix.Avalonia/App.axaml.cs
  2. 14
      StabilityMatrix.Core/Services/TrackedDownloadService.cs

3
StabilityMatrix.Avalonia/App.axaml.cs

@ -334,7 +334,10 @@ public sealed class App : Application
services.AddSingleton<IPyRunner, PyRunner>();
services.AddSingleton<IUpdateHelper, UpdateHelper>();
services.AddSingleton<INavigationService, NavigationService>();
services.AddSingleton<ITrackedDownloadService, TrackedDownloadService>();
services.AddSingleton<IDisposable>(provider =>
(IDisposable) provider.GetRequiredService<ITrackedDownloadService>());
// Rich presence
services.AddSingleton<IDiscordRichPresenceService, DiscordRichPresenceService>();

14
StabilityMatrix.Core/Services/TrackedDownloadService.cs

@ -209,8 +209,20 @@ public class TrackedDownloadService : ITrackedDownloadService, IDisposable
/// <inheritdoc />
public void Dispose()
{
foreach (var (_, fs) in downloads.Values)
foreach (var (download, fs) in downloads.Values)
{
if (download.ProgressState == ProgressState.Working)
{
try
{
download.Pause();
}
catch (Exception e)
{
logger.LogWarning(e, "Failed to pause download {Download}", download.FileName);
}
}
fs.Dispose();
}

Loading…
Cancel
Save