diff --git a/src/Eto/Forms/Form.cs b/src/Eto/Forms/Form.cs index e17fc5217..782d9f314 100755 --- a/src/Eto/Forms/Form.cs +++ b/src/Eto/Forms/Form.cs @@ -97,6 +97,18 @@ public void Show() base.Visible = true; } } + + /// + /// Shows the form with a task that can be awaited until it is closed + /// + /// Task that completes when the form is closed. + public Task ShowAsync() + { + var tcs = new TaskCompletionSource(); + Closed += (sender, e) => tcs.TrySetResult(true); + Show(); + return tcs.Task; + } /// /// Interface handler for the control diff --git a/test/Eto.Test/UnitTests/Forms/FormTests.cs b/test/Eto.Test/UnitTests/Forms/FormTests.cs index 578275f46..c5c299a51 100644 --- a/test/Eto.Test/UnitTests/Forms/FormTests.cs +++ b/test/Eto.Test/UnitTests/Forms/FormTests.cs @@ -7,13 +7,7 @@ public class FormTests : WindowTests
protected override void Test(Action test, int timeout = 4000) => Form(test, timeout); protected override void ManualTest(string message, Func test) => ManualForm(message, test); protected override void Show(Form window) => window.Show(); - protected override Task ShowAsync(Form window) - { - var tcs = new TaskCompletionSource(); - window.Closed += (sender, e) => tcs.TrySetResult(true); - window.Show(); - return tcs.Task; - } + protected override Task ShowAsync(Form window) => window.ShowAsync(); [Test, ManualTest] public void WindowShouldCloseOnLostFocusWithoutHidingParent()