I have a Windows app that I’ve written in C# 4 and WPF; I’ve now been asked if I can add a commandline parameter (e.g. /console) that would force it to run as a console app so it can be run by a task scheduler.
Is this possible with modern apps? Or do I need to create a separate console app?
UPDATE: can I just emphasise that this is a WPF application. There is no convenient static void Main(string[] args) entry point to hook into. But the PM would still like the app to have the ability to run from the commandline…
FINAL UPDATE: the trick, as pointed out by @RodH257, is that the WPF app codegens the expected static void Main. You can add your own class with a method of the same name and in the project build properties, set it as the startup object for the executable. You’ll also need the [STAThread] attribute on the method so that WPF will run properly too.
You can either turn it into a console application and manually show the first WPF dialog. just as you would if you were creating a DLL and starting a WPF window, as per below
OR, have a look at this link for editing the entrypoint on your current WPF project and act based on arguments
How to write custom Main method for a WPF application?
EDIT:
Updated the post to make it more clear for the exact situation described.