From 8ec607ba3c1d672f5aeac065dd19dc3514e209c4 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 23 Apr 2017 23:00:13 -0400 Subject: ensure SMAPI resources are disposed on exit (#268) --- src/StardewModdingAPI/Program.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 3bd91a7c..5cf80448 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -22,7 +22,7 @@ using Monitor = StardewModdingAPI.Framework.Monitor; namespace StardewModdingAPI { /// The main entry point for SMAPI, responsible for hooking into and launching the game. - internal class Program + internal class Program : IDisposable { /********* ** Properties @@ -87,8 +87,8 @@ namespace StardewModdingAPI logPath = Constants.DefaultLogPath; // load SMAPI - new Program(writeToConsole, logPath) - .LaunchInteractively(); + using (Program program = new Program(writeToConsole, logPath)) + program.RunInteractively(); } /// Construct an instance. @@ -101,7 +101,7 @@ namespace StardewModdingAPI } /// Launch SMAPI. - public void LaunchInteractively() + public void RunInteractively() { // initialise SMAPI try @@ -204,6 +204,15 @@ namespace StardewModdingAPI return this.GetSecondaryMonitor(modName); } + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + public void Dispose() + { + this.LogFile?.Dispose(); + this.ConsoleManager?.Dispose(); + this.CancellationTokenSource?.Dispose(); + this.GameInstance?.Dispose(); + } + /********* ** Private methods -- cgit