-1

What changes I need to make if I am using Caliburn Micro as the MVVM framework to make my application to run either as GUI or as a command line app (so it can be used as a Windows Service).

Macindows
  • 209
  • 3
  • 14
  • Command line applications are *not* the same thing as Windows Services. They're meant to run in the console subsystem, the thing you get by opening up the Windows Command Prompt. A Windows Service is something completely different. – Cody Gray - on strike May 20 '20 at 19:04

1 Answers1

0

Don't declare a StartupUri but instead register to the StartUp event in your Application.

In the event you could read an argument to distinguish between opening a Window or not.

So for example:

App.xaml

<Application x:Class="WpfApp1.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WpfApp1"
             Startup="App_OnStartup">
</Application>

App.xaml.cs

public partial class App : Application
{
    private void App_OnStartup(object sender, StartupEventArgs e)
    {
        if (e.Args.Contains("Console"))
        {
            //do stuff
        }
        else
        {
            new MainWindow().Show();
        }
    }
}
Rand Random
  • 7,300
  • 10
  • 40
  • 88