Просмотр исходного кода

Fixes FileSystemWatcher exception on Linux. (#1600)

BDisp 3 лет назад
Родитель
Сommit
0be59c9bc5
2 измененных файлов с 26 добавлено и 0 удалено
  1. 15 0
      Terminal.Gui/Windows/FileDialog.cs
  2. 11 0
      UnitTests/ToplevelTests.cs

+ 15 - 0
Terminal.Gui/Windows/FileDialog.cs

@@ -94,6 +94,21 @@ namespace Terminal.Gui {
 			return valid;
 			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)
 		void Watcher_Error (object sender, ErrorEventArgs e)
 		{
 		{
 			Application.MainLoop.Invoke (() => Reload ());
 			Application.MainLoop.Invoke (() => Reload ());

+ 11 - 0
UnitTests/ToplevelTests.cs

@@ -647,5 +647,16 @@ namespace Terminal.Gui.Core {
 			Assert.Equal (Key.PageUp | Key.CtrlMask, Application.AlternateBackwardKey);
 			Assert.Equal (Key.PageUp | Key.CtrlMask, Application.AlternateBackwardKey);
 			Assert.Equal (Key.Q | Key.CtrlMask, Application.QuitKey);
 			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);
+			}
+		}
 	}
 	}
 }
 }