I've got an hybrid application with either console or WPF functionality. If the WPF application is started or something is done in console window depends on the arguments at start up. I were able to implement this (there are a lot of examples to find at stackoverflow). Now I want that, if the WPF application is started, that the console window will be closed. But this is shown and if I close it, the WPF application is also closed.
This is my current implementation.
using System;
using System.Windows;
namespace MyNamespace
{
class Program
{
[STAThread]
static void Main(string[] args)
{
string option = args[0];
switch (option)
{
case "WPF":
RunApplication();
break;
default:
DoSomething();
break;
}
}
private static void RunApplication()
{
Application app = new Application();
app.Run(new MainWindow());
Environment.Exit(0);
}
private static void DoSomething()
{
// …
}
}
}
If I try to start the application in a new Thread
the application is directly closed and the WPF window will not be shown.
using System.Threading;
using System.Threading.Tasks;
private static void RunApplication()
{
new Thread(() => {
Application app = new Application();
app.Run(new MainWindow());
}).Start();
Environment.Exit(0);
}
I have no idea how I could implement this. Is there a possibility to do this?