diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-04-23 23:00:13 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-04-23 23:00:13 -0400 |
commit | 8ec607ba3c1d672f5aeac065dd19dc3514e209c4 (patch) | |
tree | 74fe3f7c6a27a57b254d49540b4966c1a32d67c5 /src | |
parent | 07197fac9dbea84565f6004029b15667c9c2b038 (diff) | |
download | SMAPI-8ec607ba3c1d672f5aeac065dd19dc3514e209c4.tar.gz SMAPI-8ec607ba3c1d672f5aeac065dd19dc3514e209c4.tar.bz2 SMAPI-8ec607ba3c1d672f5aeac065dd19dc3514e209c4.zip |
ensure SMAPI resources are disposed on exit (#268)
Diffstat (limited to 'src')
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 17 |
1 files changed, 13 insertions, 4 deletions
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 { /// <summary>The main entry point for SMAPI, responsible for hooking into and launching the game.</summary> - 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(); } /// <summary>Construct an instance.</summary> @@ -101,7 +101,7 @@ namespace StardewModdingAPI } /// <summary>Launch SMAPI.</summary> - public void LaunchInteractively() + public void RunInteractively() { // initialise SMAPI try @@ -204,6 +204,15 @@ namespace StardewModdingAPI return this.GetSecondaryMonitor(modName); } + /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary> + public void Dispose() + { + this.LogFile?.Dispose(); + this.ConsoleManager?.Dispose(); + this.CancellationTokenSource?.Dispose(); + this.GameInstance?.Dispose(); + } + /********* ** Private methods |