Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run code once and exit formless app: Windows Forms or WPF... does it matter?

Tags:

c#

I need to write a very small application which writes some system data to a file and then exits. I could do this in a console application but I have no need or desire for a console window to appear during this process.

I would normally use a Windows Forms application with no forms, execute the code in the Main method and then allow the application to exit, however, this time I couldn't help but wonder if this is the best way to do it and whether you could do it with a WPF application instead, what the differences are and whether or not once you've remove any forms/windows and unnecessary reference, it matters or not.

like image 865
Ashigore Avatar asked Dec 07 '25 21:12

Ashigore


1 Answers

WPF and WinForms are two different libraries that show UIs.

If you never show a UI, you aren't using either of them.
You should start with a WinForms project (WPF projects set extra project metadata that you don't want), then delete the reference to System.Windows.Forms.dll.

Alternatively, start with a console project, then change the Output type to Windows Application.

like image 77
SLaks Avatar answered Dec 10 '25 22:12

SLaks