diff --git a/.editorconfig b/.editorconfig index a862120ab..6974870cd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -111,7 +111,6 @@ dotnet_diagnostic.ca1028.severity = silent dotnet_diagnostic.ca1031.severity = silent # TODO - one at a time -dotnet_diagnostic.ca1063.severity = silent dotnet_diagnostic.ca1303.severity = silent dotnet_diagnostic.ca1307.severity = silent dotnet_diagnostic.ca1308.severity = silent diff --git a/ArchiSteamFarm/BotDatabase.cs b/ArchiSteamFarm/BotDatabase.cs index 6623f981d..1a8c608ad 100644 --- a/ArchiSteamFarm/BotDatabase.cs +++ b/ArchiSteamFarm/BotDatabase.cs @@ -106,15 +106,20 @@ namespace ArchiSteamFarm { MatchActivelyBlacklistedAppIDs.OnModified += OnObjectModified; } - public override void Dispose() { - BlacklistedFromTradesSteamIDs.OnModified -= OnObjectModified; - IdlingBlacklistedAppIDs.OnModified -= OnObjectModified; - IdlingPriorityAppIDs.OnModified -= OnObjectModified; - MatchActivelyBlacklistedAppIDs.OnModified -= OnObjectModified; + protected override void Dispose(bool disposing) { + if (disposing) { + // Events we registered + BlacklistedFromTradesSteamIDs.OnModified -= OnObjectModified; + IdlingBlacklistedAppIDs.OnModified -= OnObjectModified; + IdlingPriorityAppIDs.OnModified -= OnObjectModified; + MatchActivelyBlacklistedAppIDs.OnModified -= OnObjectModified; - BackingMobileAuthenticator?.Dispose(); + // Those are objects that might be null and the check should be in-place + BackingMobileAuthenticator?.Dispose(); + } - base.Dispose(); + // Base dispose + base.Dispose(disposing); } internal void AddGamesToRedeemInBackground(IOrderedDictionary games) { diff --git a/ArchiSteamFarm/GlobalDatabase.cs b/ArchiSteamFarm/GlobalDatabase.cs index 0000df6f6..9e05dc478 100644 --- a/ArchiSteamFarm/GlobalDatabase.cs +++ b/ArchiSteamFarm/GlobalDatabase.cs @@ -107,15 +107,17 @@ namespace ArchiSteamFarm { [JsonConstructor] private GlobalDatabase() => ServerListProvider.ServerListUpdated += OnObjectModified; - public override void Dispose() { - // Events we registered - ServerListProvider.ServerListUpdated -= OnObjectModified; + protected override void Dispose(bool disposing) { + if (disposing) { + // Events we registered + ServerListProvider.ServerListUpdated -= OnObjectModified; - // Those are objects that are always being created if constructor doesn't throw exception - PackagesRefreshSemaphore.Dispose(); + // Those are objects that are always being created if constructor doesn't throw exception + PackagesRefreshSemaphore.Dispose(); + } // Base dispose - base.Dispose(); + base.Dispose(disposing); } internal static async Task CreateOrLoad(string filePath) { diff --git a/ArchiSteamFarm/Helpers/SerializableFile.cs b/ArchiSteamFarm/Helpers/SerializableFile.cs index 2f33f3563..5d2f94109 100644 --- a/ArchiSteamFarm/Helpers/SerializableFile.cs +++ b/ArchiSteamFarm/Helpers/SerializableFile.cs @@ -34,12 +34,17 @@ namespace ArchiSteamFarm.Helpers { private bool ReadOnly; private bool SavingScheduled; - public virtual void Dispose() { - FileSemaphore.Dispose(); - + public void Dispose() { + Dispose(true); GC.SuppressFinalize(this); } + protected virtual void Dispose(bool disposing) { + if (disposing) { + FileSemaphore.Dispose(); + } + } + protected async Task Save() { if (string.IsNullOrEmpty(FilePath)) { throw new InvalidOperationException(nameof(FilePath));