Skip to content

Commit

Permalink
Merge pull request #2706 from cwensley/curtis/add-form-showasync
Browse files Browse the repository at this point in the history
Add Form.ShowAsync
  • Loading branch information
cwensley authored Nov 25, 2024
2 parents cb4c7ed + 5d79e65 commit 5c614f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/Eto/Forms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public void Show()
base.Visible = true;
}
}

/// <summary>
/// Shows the form with a task that can be awaited until it is closed
/// </summary>
/// <returns>Task that completes when the form is closed.</returns>
public Task ShowAsync()
{
var tcs = new TaskCompletionSource<bool>();
Closed += (sender, e) => tcs.TrySetResult(true);
Show();
return tcs.Task;
}

/// <summary>
/// Interface handler for the <see cref="Form"/> control
Expand Down
8 changes: 1 addition & 7 deletions test/Eto.Test/UnitTests/Forms/FormTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ public class FormTests : WindowTests<Form>
protected override void Test(Action<Form> test, int timeout = 4000) => Form(test, timeout);
protected override void ManualTest(string message, Func<Form, Control> test) => ManualForm(message, test);
protected override void Show(Form window) => window.Show();
protected override Task ShowAsync(Form window)
{
var tcs = new TaskCompletionSource<bool>();
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()
Expand Down

0 comments on commit 5c614f4

Please sign in to comment.