diff --git a/Terminal.Gui/Windows/FileDialog.cs b/Terminal.Gui/Windows/FileDialog.cs index 35bb56937..d078757eb 100644 --- a/Terminal.Gui/Windows/FileDialog.cs +++ b/Terminal.Gui/Windows/FileDialog.cs @@ -94,6 +94,21 @@ namespace Terminal.Gui { return valid; } + private bool _disposedValue; + protected override void Dispose (bool disposing) + { + if (!_disposedValue) { + if (disposing) { + watcher?.Dispose (); + } + + _disposedValue = true; + } + + // Call base class implementation. + base.Dispose (disposing); + } + void Watcher_Error (object sender, ErrorEventArgs e) { Application.MainLoop.Invoke (() => Reload ()); diff --git a/UnitTests/ToplevelTests.cs b/UnitTests/ToplevelTests.cs index 1466e579b..0dee08b06 100644 --- a/UnitTests/ToplevelTests.cs +++ b/UnitTests/ToplevelTests.cs @@ -647,5 +647,16 @@ namespace Terminal.Gui.Core { Assert.Equal (Key.PageUp | Key.CtrlMask, Application.AlternateBackwardKey); Assert.Equal (Key.Q | Key.CtrlMask, Application.QuitKey); } + + [Fact] + [AutoInitShutdown] + public void FileDialog_FileSystemWatcher () + { + for (int i = 0; i < 256; i++) { + var fd = new FileDialog (); + fd.Ready += () => Application.RequestStop (); + Application.Run (fd); + } + } } } \ No newline at end of file