How to run a .NET console application in the background
I have a console application written in C# that is scheduled to run every 15 minutes or so using the built-in Windows Task Scheduler.
Every time it runs, the black console box pops up for the duration of its execution and then closes. I am not writing anything to the console. Is there a way to make this run in the background?
Project > Properties> Application tab > change Output type to "Windows application".
No more console window.
Easy!
It seems hard to believe, but it works as a charm. I have used this for some setup projects, when you want to perform custom tasks with no signs of it.
- Create the project as a Windows application project (this is the hard part).
-
Never make calls to any form. Just keep on in exactly as in your console application
class Program { static void Main(string[] args) { // Just don't call Application.Run(new frmMain(args)); // ... your code } }
This is because windows application projects are no really different than console, except because of the first form and references. It is totally hidden execution. Try it!