Creating Background Applications in C#

.NET supports three types of executable applications out of the box: console, windows (forms), and service. (Actually, it also supports WPF, but that’s not the point.)

Console applications run with that old DOS-style window. They typically take input, and flood output on the console. They run, process, and execute in a finite lifetime.

Windows applications have some sort of windows form that they show. You can interact with them via buttons, lists, drop-downs, and more:

A windows service runs in the background. It starts when Windows starts, and stops when Windows shuts down. There’s no GUI; it just runs.

It’s pretty well-known how to create any of these application types in .NET. But what about a background process?

But first, what is a background process? It’s something like a mix between a console application and a Windows service; it runs in the background and executes code without any UI (like a service), but has a particular lifetime less than the lifetime of Windows (like a console application).

Why would you want to create a background process? Hopefully not to create a virus, malware, adware, or something else malicious (if that’s the case, please read about it elsewhere!).

It might be, as the case was for me, that you have an existing application which needs to perform some sort of task in the background: performing maintenance, checking for updates, or things like that.

The solution is pretty simple: just create a Windows Application project which doesn’t invoke any forms. You can do this by creating a new Windows Forms application and deleting the main form, or by creating a console application and changing the output type to Windows Application in the project properties:

That’s really all there is to it; your application will execute without any visible GUI or console window.

About Ashiq Alibhai, PMP

Ashiq has been coding C# since 2005. A desktop, web, and RIA application developer, he's touched ASP.NET MVC, ActiveRecord, Silverlight, NUnit, and all kinds of exciting .NET technologies. He started C# City in order to accelerate his .NET learning.
This entry was posted in Core .NET, Wndows Forms and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *