简体   繁体   中英

How Can I Suppress the Black Shell that Pops Up When I Run my C# Winforms Application?

When I run my C# application (compiled in VS, Release build) by clicking on the.exe file, I get a black shell along with my GUI. I'm not sure why this black shell appears, as it doesn't appear in any of my other GUI applications. How can I suppress the black shell? Did I accidentally click on something I shouldn't have before compilation?

As you can see below, my GUI application and the black shell (behind the application).

在此处输入图像描述

The following is my directory structure where the application is executing out of:

在此处输入图像描述

If the "Output Type" of the project 1 is accidentally changed from "Windows Application" to "Console Application", you'll get symptoms very much like this.

Assuming you started out with the Windows application template, your main thread will still be STA and nothing stops a console application from running a windows message loop and displaying UI (as the template will have set up). But you do always get a console window attached to a Console Application.

If this has happened, you just need to change the Output Type back to Windows Application.


1 Project properties, Application tab.

By default, a Winforms application doesn't show a console, this is something that you need to actively call for. The way this is typically done is by calling the native AllocConsole function:

https://www.pinvoke.net/default.aspx/kernel32.allocconsole

I would search through the codebase and see if AllocConsole is being called anywhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM