Hide Console Window in C# Console Application

.NetConsole Application

.Net Problem Overview


The thing is, I really don't want the console window to show up, but the solution should be running. My point here is, I want to keep the application running in the background, without any window coming up.

How can I do that?

.Net Solutions


Solution 1 - .Net

Change the output type from Console Application to Windows Application. This can be done under Project -> Properties -> Application in Visual Studio:

alt text

Solution 2 - .Net

Change your application type to a windows application. Your code will still run, but it will have no console window, nor standard windows window unless you create one.

Solution 3 - .Net

Instead of Console.Readline/key you can use new ManualResetEvent(false).WaitOne() at last. This works well for me.

Solution 4 - .Net

You can use user32.dll to achieve this without vscode

    class start
    {
        [DllImport("user32.dll")]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        static void Main()
        {
            IntPtr h = Process.GetCurrentProcess().MainWindowHandle;
            ShowWindow(h, 0);
            // Do the rest

This still flashes the screen but works good enough

the usings are

using System.Runtime.InteropServices;
using System.Diagnostics;

Note im still new to csharp and not perfect so feel free to comment and corrections!

Solution 5 - .Net

Maybe you want to try creating a Windows Service application. It will be running in the background, without any UI.

Solution 6 - .Net

Change the output type from Console Application to Windows Application,

And Instead of Console.Readline/key you can use new ManualResetEvent(false).WaitOne() at the end to keep the app running.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSOF UserView Question on Stackoverflow
Solution 1 - .NetDirk VollmarView Answer on Stackoverflow
Solution 2 - .NetSekhatView Answer on Stackoverflow
Solution 3 - .Netkhaja kamalView Answer on Stackoverflow
Solution 4 - .NetJonathan ColettiView Answer on Stackoverflow
Solution 5 - .NetblaView Answer on Stackoverflow
Solution 6 - .NetN TView Answer on Stackoverflow