dotnet / dotnet/winforms

Inconsistencies between Show() and ShowAsync()

Open
#14,201 4 comments 3 reactions 1 assignee Claimed by @KlausLoeffelmann View on GitHub
needs-area-label untriaged
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

### .NET version

.NET 10.0.101

### Did it work in .NET Framework?

Not available

### Did it work in any of the earlier releases of .NET Core or .NET 5+?

Not available

### Issue description

Highly appreciate the async extensions for WinForms #4631 & #11854. This helps a lot and I have really been looking forward to this.
However, we found out that the new async methods behave differently in three cases:

1. **Showing async MDI children**
MDI child forms cannot be shown asynchronously. For most business apps this is exactly the point where it should be supported given that all the forms the users are working with are usually MDI children.

2. **`ShowAsync()` without an `IWin32Owner` does not set an owner but behaves like it would**
In the demo app, if you leave all checkboxes unset, you'll get a new form that can also get behind the main form.
If you check the Async checkbox only, the form will not get a parent and no owner. And still it behaves like it would have an owner.
What I mean by this is while the main form is not blocked and can be used while the created form stays open, the main form cannot cover the created form. The created form will always stay on top, just like it is the case with `Show()` with an owner.

3. **Calling `Show()`/`ShowAsync()` twice**
While it makes no sense to do this, we found out that the behavior differs when calling `Show()` multiple times (no error) vs. calling `ShowAsync()` multiple times, which leads to exceptions.
Why is that and can this be changed to behave the same? I think the behavior of `Show()` is better here as it might just be setting `Visible=true`, which can be done multiple times as well.

### Steps to reproduce

I created a tiny repro app where all of this can be tested easily.
→ https://github.com/awaescher/AsyncFormsRepro

Just clone it and run `dotnet run --project AsyncForms`.

![Screenshot of the repro app](https://raw.githubusercontent.com/awaescher/AsyncFormsRepro/main/Screenshot.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.