Reputation: 7840
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?
Upvotes: 122
Views: 108058
Reputation: 1
To compile your application without a console window
csc.exe /target:winexe *.cs
Upvotes: 0
Reputation: 528
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!
Upvotes: 5
Reputation: 456
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.
Upvotes: 3
Reputation: 141
Instead of Console.Readline/key
you can use new ManualResetEvent(false).WaitOne()
at last. This works well for me.
Upvotes: 14
Reputation: 5480
Maybe you want to try creating a Windows Service application. It will be running in the background, without any UI.
Upvotes: 3
Reputation: 4489
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.
Upvotes: 28
Reputation: 176239
Change the output type from Console Application to Windows Application. This can be done under Project -> Properties -> Application in Visual Studio:
Upvotes: 217