Skip to content

Fixing ShowInTaskbar=false doesn't work in some cases (#6421)#6989

Merged
Tanya-Solyanik merged 8 commits intomainfrom
unknown repository
Apr 18, 2022
Merged

Fixing ShowInTaskbar=false doesn't work in some cases (#6421)#6989
Tanya-Solyanik merged 8 commits intomainfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Apr 8, 2022

Fixes #6421.

If you set ShowInTaskbar=false, the winforms will recreate the Handle. It will call RecreateHandleCore() from Control.cs.

In method WmNCDestroy(ref Message m) from class Form.cs, The program needs to confirm whether the handle is being recreated before setting the value of the DialogResult.

If the program is in the process of recreating the handle, setting DialogResult = DialogResult.Cancel will cause the Form to be automatically closed.

Microsoft Reviewers: Open in CodeFlow

@ghost ghost self-requested a review as a code owner April 8, 2022 13:13
@ghost ghost self-assigned this Apr 8, 2022
@Tanya-Solyanik
Copy link
Contributor

Looks good, could you please add unit test for this case

@ghost
Copy link
Author

ghost commented Apr 9, 2022

@Tanya-Solyanik Thank you. I have tested it on my machine. I am new to this, do you have a spec document so I can learn how to make unit tests that conform to the .net spec? Because this change actually only adjusts one line of the statement. I'm not sure about the test system's rules for dealing with such changes.

@Tanya-Solyanik
Copy link
Contributor

@roland5572 - you could use this https://github.com/dotnet/winforms/blob/main/docs/testing.md as a starting point.

@ghost
Copy link
Author

ghost commented Apr 10, 2022

@Tanya-Solyanik Thank you. Do you prefer a unit test for current issue, or a unit test specifically tests a function that has been fixed?

@Tanya-Solyanik
Copy link
Contributor

Do you prefer a unit test for current issue, or a unit test specifically tests a function that has been fixed?

Ha-ha, may I have both please?

I meant the current issue. We are aiming to accompany fixes with "regression" tests that cover specific issues being fixed. But if you have time to cover this functionality, such a PR will always be welcome.

@ghost
Copy link
Author

ghost commented Apr 11, 2022

Thank you. I am learning to make unit tests. I'll try to get it done over the weekend.

@Tanya-Solyanik Tanya-Solyanik added the waiting-author-feedback The team requires more information from the author label Apr 11, 2022
@RussKie
Copy link
Contributor

RussKie commented Apr 11, 2022 via email

@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Apr 15, 2022
@dnfadmin
Copy link

dnfadmin commented Apr 15, 2022

CLA assistant check
All CLA requirements met.

@ghost
Copy link
Author

ghost commented Apr 15, 2022

Thank you, I have added unit test.

Copy link
Contributor

@Tanya-Solyanik Tanya-Solyanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding a test! I added some nits


control.Load += (object sender, EventArgs e) =>
{
control.ShowInTaskbar = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to confirm that handle had been re-created? Perhaps compare handle values? Or read the state?

Copy link
Author

@ghost ghost Apr 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this Issue, Handle is bound to be created successfully. This Issue is not caused by the failure to create the Handle, but in the process of creating the Handle, a statement calls the statement that automatically closes the window. If you tend to compare handles, I'll add that.


control.ShowDialog();

Assert.Equal(prefValue, control.DialogResult);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm that the handle had been created.

@ghost
Copy link
Author

ghost commented Apr 16, 2022

@Tanya-Solyanik Thank you. I have modified all the code according to your suggestion, and added a manual test.

Tanya-Solyanik
Tanya-Solyanik previously approved these changes Apr 17, 2022
Copy link
Contributor

@Tanya-Solyanik Tanya-Solyanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Looks good

@ghost ghost requested a review from Tanya-Solyanik April 17, 2022 12:07
Copy link
Contributor

@Tanya-Solyanik Tanya-Solyanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@Tanya-Solyanik Tanya-Solyanik merged commit 93c7049 into dotnet:main Apr 18, 2022
@ghost ghost added this to the 7.0 Preview4 milestone Apr 18, 2022
@AraHaan
Copy link
Member

AraHaan commented Apr 18, 2022

Will this go into a servicing release for .NET 6 @Tanya-Solyanik?

@ghost ghost deleted the fix6421 branch April 18, 2022 07:38
@dreddy-work
Copy link
Member

@AraHaan , given this has been the behavior since .NET framework, it wouldn't meet the servicing bar unless there is a business justification on customer impact.

@AraHaan
Copy link
Member

AraHaan commented Apr 19, 2022

So basically winforms programs targeting .NET 6 (and might be production quality) will still be broken by this as it won't be serviced as they cannot target .NET 7 yet until RC at least?

@RussKie
Copy link
Contributor

RussKie commented Apr 19, 2022

So basically winforms programs targeting .NET 6 (and might be production quality) will still be broken by this as it won't be serviced as they cannot target .NET 7 yet until RC at least?

Since this was an existing issue apps targeting .NET 6.0 aren't affected by this issue any more than apps targeting .NET Framework.

@ghost ghost locked as resolved and limited conversation to collaborators May 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting ShowInTaskbar to false causes the form to close automatically (Abnormal exit).

6 participants