diff --git a/Core/Registry/RegistryManager.cs b/Core/Registry/RegistryManager.cs index ef78bd7148..13cb2578ad 100644 --- a/Core/Registry/RegistryManager.cs +++ b/Core/Registry/RegistryManager.cs @@ -20,6 +20,7 @@ public class RegistryManager : IDisposable private readonly string path; public readonly string lockfile_path; private FileStream lockfile_stream = null; + private StreamWriter lockfile_writer = null; private readonly TxFileManager file_transaction = new TxFileManager(); @@ -110,9 +111,9 @@ public bool GetLock() lockfile_stream = new FileStream(lockfile_path, FileMode.CreateNew, FileAccess.Write, FileShare.None, 512, FileOptions.DeleteOnClose); // Write the current process ID to the file. - StreamWriter writer = new StreamWriter(lockfile_stream); - writer.Write(Process.GetCurrentProcess().Id); - writer.Flush(); + lockfile_writer = new StreamWriter(lockfile_stream); + lockfile_writer.Write(Process.GetCurrentProcess().Id); + lockfile_writer.Flush(); } catch (IOException) { @@ -132,6 +133,13 @@ public void ReleaseLock() lockfile_stream.Close(); lockfile_stream = null; } + + // This may not be needed when the underlying stream is closed, + // but doesn't hurt. + if (lockfile_writer != null) + { + lockfile_writer.Dispose(); + } } ///