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?
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?
Change the output type from Console Application to Windows Application. This can be done under Project -> Properties -> Application in Visual Studio:
Console.ReadLine
. It doesn't make any sense if you don't have a console window. –
Cervix 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.
Instead of Console.Readline/key
you can use new ManualResetEvent(false).WaitOne()
at last. This works well for me.
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!
Maybe you want to try creating a Windows Service application. It will be running in the background, without any UI.
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.
To compile your application without a console window
csc.exe /target:winexe *.cs
© 2022 - 2024 — McMap. All rights reserved.