Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ghost opened this issue Dec 26, 2021 · 30 comments · Fixed by #6989
Closed

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

ghost opened this issue Dec 26, 2021 · 30 comments · Fixed by #6989

Comments

@ghost
Copy link

ghost commented Dec 26, 2021

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

https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form

Test Code:
.NET 6.0 (Version: 6.0.1)(This problem also appears in .net framework 4.8)
Win10 system (21H2).

using System;
using System.Windows.Forms;

namespace FormShowInTaskbarTest
{
    internal static class Program
    {
        private static Form form1;
        private static Form form2;

        [STAThread]
        static void Main()
        {
            ApplicationConfiguration.Initialize();

            form1 = new Form()
            {
                Width = 800,
                Height = 600,
                StartPosition = FormStartPosition.CenterScreen,
            };

            var button1 = new Button()
            {
                Text = "Click here to open new Form.",

                Width = 200,
                Height = 100,
            };

            button1.Click += Button1_Click;
            form1.Controls.Add(button1);

            Application.Run(form1);
        }

        private static void Button1_Click(object sender, EventArgs e)
        {
            form2 = new Form()
            {
                Width = 600,
                Height = 400,

                StartPosition = FormStartPosition.CenterScreen,
            };

            var button2 = new Button()
            {
                Text = "Click here to test ShowInTaskbar.",

                Width = 200,
                Height = 100,
            };

            button2.Click += Button2_Click;
            form2.Controls.Add(button2);

            form2.ShowDialog(form1);
        }

        private static void Button2_Click(object sender, EventArgs e)
        {
            form2.ShowInTaskbar = false;
        }
    }
}

Steps to reproduce:

  1. Run the appliction.
  2. Click the first button, the application will open a new Form.
  3. Click the first button in new form.
@ghost ghost changed the title Setting ShowInTaskbar to false causes the form to close automatically. Setting ShowInTaskbar to false causes the form to close automatically (Abnormal exit). Dec 26, 2021
@AraHaan
Copy link
Member

AraHaan commented Dec 29, 2021

This is odd because in my program it works just fine (even when using 7.0.0-dev runtime) 🤔 (And I change it in a Timer when the application's own settings change from displaying the icon in taskbar to tray or to both).

@ghost
Copy link
Author

ghost commented Dec 29, 2021

This is odd because in my program it works just fine (even when using 7.0.0-dev runtime) 🤔 (And I change it in a Timer when the application's own settings change from displaying the icon in taskbar to tray or to both).

Did you use Win7 or Win11? I am running on Win10 system (21H2) with .NET 6.0 (Version: 6.0.1). I just used a clean Win10 computer for testing, and it was running on .net 5.0 (Version: 5.0.0, No patch), and the same problem occurred.

@AraHaan
Copy link
Member

AraHaan commented Dec 29, 2021

I use Windows 11 on my old computer (that had 11 since it was in preview), and my newer one and it seems to work fine with 6.0.0, 6.0.1, and 7.0.0-dev.

@ghost
Copy link
Author

ghost commented Dec 29, 2021

I use Windows 11 on my old computer (that had 11 since it was in preview), and my newer one and it seems to work fine with 6.0.0, 6.0.1, and 7.0.0-dev.

I just used Win11 for testing. I used the test code above. Found the same problem. I am not sure if this problem can be avoided by other codes in your program.

@fahadabdulaziz
Copy link

I can confirm this problem using Win10 21H2, on .NET 6.0.1 but not Win10 21H2 .NET 6.0.0.
Maybe #6115 is related.

@AraHaan
Copy link
Member

AraHaan commented Jan 2, 2022

Odd I now run into this issue now with manually built runtime running at the tip of branch main.

@AraHaan
Copy link
Member

AraHaan commented Jan 2, 2022

I think it could be that I hide the form the first thing right on the load event on my forms program causing it to terminate ironically right after it loads TerraFX.Interop.Windows 😄.

Yes ironically it uses this API when the user configures for the program to not display it in the Taskbar.

@John-Qiao
Copy link
Member

Add test app here: TestApp6421.zip

@AraHaan
Copy link
Member

AraHaan commented Jan 10, 2022

I will be testing the changes in #6477 to ensure my program now properly runs the way it was before I installed the 6.0.1 servicing (however it will be the changes in the main branch as I was testing it with an updated zlib impl on the base runtime I was already making that was proposed into .NET 7).

@AraHaan
Copy link
Member

AraHaan commented Jan 14, 2022

So, was the cause of this found as I use this on my main program by default on startup which seems to cause it to instantly close in .NET 7. I got reports that a user who done a clone and did a clean build in .NET 6's latest 6.0.2 patch seems to work fine on their end (or so it looked like it did).

@RussKie
Copy link
Member

RussKie commented Jan 18, 2022

I have run the provided sample on Win11 (10.0.22000 Build 22000), and confirmed the behaviour is consistent as far as .NET Framework 4.7.2 and all the way up to .NET 7 Preview1.

@Olina-Zhang would you be able to test 6421.zip on different versions of Windows 10 and see if there are any differences in behaviours? Thank you.

@RussKie RussKie added the waiting-on-team This work item needs to be discussed with team or is waiting on team action in order to proceed label Jan 18, 2022
@John-Qiao
Copy link
Member

@RussKie we have tested the sample project on 9 different Win10 OSs(20H2, 20H1, 19H1, 19H2, RS5, RS4, RS3, RS2, RS1), they are all the same result when target to .NET 7.0 or .NET 6.0 or .NET Framework 4.7.2 or .NET Framework 4.8.

@AraHaan
Copy link
Member

AraHaan commented Jan 19, 2022

What is the result with running it in 8, 8.1 and 7 with .NET 7.0?

@John-Qiao
Copy link
Member

@AraHaan It's the same result in 8.1 and 7 with .NET 7.0.

@ghost
Copy link
Author

ghost commented Jan 20, 2022

@John-Qiao Do you mean the test result is OK, or it's Failed? I just re-tested on my computer. It does not work with .net 6.0. If you need, I can provide the version number of the operating system and the video to you.

@John-Qiao
Copy link
Member

@roland5572 I mean the issue is still reproduced in that environments: click the button in new form will close the new form automatically.

@AraHaan
Copy link
Member

AraHaan commented Jan 22, 2022

Hmm I wonder if it's due to the implementation of the property itself, if only I could add the Windows Forms code as a local project reference just so I can set breakpoints on it in my code to know for sure if that property is what causes my program to randomly terminate.

Then if so, I will need to figure out ways of doing the same thing without terminating any forms (perhaps have the runtime create a dummy parent form for a form that is not visible so then it makes it not applicable to have an taskbar entry.

However what about cases of programs with forms where the parent form is both shown in tray & taskbar and it's designed to show the settings and about forms without either one as that button brings it all to focus anyway and the parent form can be configured at any time to not show the tray or not show in taskbar as well (as 3 options in settings total) with a timer in the parent that reads the saved settings?

@RussKie
Copy link
Member

RussKie commented Jan 24, 2022

if only I could add the Windows Forms code as a local project reference just so I can set breakpoints on it in my code to know for sure if that property is what causes my program to randomly terminate.

Try this https://github.com/dotnet/winforms/blob/main/docs/debugging.md.

@RussKie RussKie added 📭 waiting-author-feedback The team requires more information from the author waiting-on-team This work item needs to be discussed with team or is waiting on team action in order to proceed and removed waiting-on-team This work item needs to be discussed with team or is waiting on team action in order to proceed 📭 waiting-author-feedback The team requires more information from the author labels Jan 24, 2022
@ghost ghost added the 🚧 work in progress Work that is current in progress label Apr 8, 2022
Tanya-Solyanik pushed a commit to Tanya-Solyanik/winforms that referenced this issue Apr 15, 2022
Tanya-Solyanik pushed a commit to Tanya-Solyanik/winforms that referenced this issue Apr 15, 2022
@ghost ghost removed the 🚧 work in progress Work that is current in progress label Apr 18, 2022
Tanya-Solyanik pushed a commit that referenced this issue Apr 18, 2022
Fixed #6421 - do not exit the form when changing ShowInTaskbar property and re-creating handle
* Add unit test
* Add manual test to Form.ShowInTaskbar
@AraHaan
Copy link
Member

AraHaan commented Apr 18, 2022

if only I could add the Windows Forms code as a local project reference just so I can set breakpoints on it in my code to know for sure if that property is what causes my program to randomly terminate.

Try this https://github.com/dotnet/winforms/blob/main/docs/debugging.md.

Too bad we cant debug using the sources downloaded from sourcelink to set breakpoints so we can debug the actual binaries that get installed from the stable builds of the sdk.

@RussKie
Copy link
Member

RussKie commented Apr 18, 2022 via email

@ghost
Copy link
Author

ghost commented Apr 24, 2022

@AraHaan

You can debug .net WinForms.

  1. Download the source code from https://github.com/dotnet/winforms
  2. Since the master branch is always improving, if you cannot compile the source code, you may need to download a stable branch (eg. v7.0.0-preview.3.22176.3 or new in the feature).
  3. unzip the source code to a folder.
  4. run build.cmd
  5. run start-vs.cmd file from your folder (You need to call this file every time you open Visual Studio. Otherwise you won't be able to debug .net).
  6. In this solution, you can add your own Forms to WinformsControlsTest project, if you cannot find it, just search it.
  7. Run WinformsControlsTest project, and now you can debug or breakpoint at any time.

@AraHaan
Copy link
Member

AraHaan commented Apr 24, 2022

If I am doing all of that work, why not publish the projects that allow one to do the same type of integration tests that this repo uses so they can test their own code too? 😄

Talking about publish as in to a nuget package.

@ghost
Copy link
Author

ghost commented Apr 24, 2022

@AraHaan Maybe the integration tests are not in the current roadmap. This method is currently the most effective.

@RussKie
Copy link
Member

RussKie commented Apr 26, 2022

If I am doing all of that work, why not publish the projects that allow one to do the same type of integration tests that this repo uses so they can test their own code too? 😄

If you have any proposals, you'd like to discuss, or have any questions - please start a new discussion thread.

@Ashley-Li
Copy link

Verified this issue on .NET 7.0.100-preview.4.22227.3, issue was fixed, click the button in new form will not close the new form automatically. TestApp4621.zip
verify_6421

@AraHaan
Copy link
Member

AraHaan commented Apr 28, 2022

Verified this issue on .NET 7.0.100-preview.4.22227.3, issue was fixed, click the button in new form will not close the new form automatically. TestApp4621.zip verify_6421

you mean preview.5.22227.3?

@Ashley-Li
Copy link

@AraHaan Yesterday, I installed Release/7.0.1xx-preview4(7.0.x Runtime) from https://github.com/dotnet/installer and test this.

@AraHaan
Copy link
Member

AraHaan commented Apr 29, 2022

I see, I been actually looking for the link to download only the daily quality Windows Desktop and ASP.NET Runtimes as it seems that the sdk installer seems to always not install the exact matching version suffix builds.

@RussKie
Copy link
Member

RussKie commented May 2, 2022

@AraHaan I don't think there's a way of doing this (outside the team).

@kant2002 has created a service that can help determining what versions the installer has, you can find it here: https://kant2002.github.io/dotnet-installer-viewer/.
E.g.,
image

@AraHaan
Copy link
Member

AraHaan commented May 2, 2022

Wait why is System.Private.Winforms preview 4 still?

Sad it don't add an download link that links to the azureblobstorage location of them either.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 1, 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 a pull request may close this issue.

5 participants