I am trying to make a WPF application that can also be run from the command line. I have a WPF app that that I am able to achieve this to some extent with. It is possible to run with 0 arguments and a window will load.
When I run it with > 0 arguments the idea is to have it run from the command line and thus should print to the command line. So for this I have Attached a console and then Freed the console after I am done.
However the following results on the command line when everything is finished.
I am able to run another command here but why isn't it displaying the full directory to make it clear that it has finished?
Is there anyway this can be resolved?
On further inspection I have noticed that it seems to be printing the new line before the output rather than after.
public partial class App : Application
{
[DllImport("Kernel32.dll")]
public static extern bool AttachConsole(int processId);
[DllImport("Kernel32.dll")]
private static extern bool FreeConsole();
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (e.Args.Length > 0)
{
AttachConsole(-1);
Console.WriteLine("\nStart");
Console.WriteLine("Stop");
Console.WriteLine("");
FreeConsole();
}
else
{
new MainWindow().ShowDialog();
}
this.Shutdown();
}
}