I am trying to process command line arguments for my WPF application for this I have made following changes
I have converted the output type as - Console Application
commented the StartupUri parameter in App.xaml
and override the protected override void OnStartup(StartupEventArgs e) { }
Here is my overridden method
public partial class App : Application
{
[DllImport("Kernel32.dll")]
public static extern bool AttachConsole(int processId);
[DllImport("Kernel32.dll")]
public static extern bool FreeConsole();
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (e.Args != null && e.Args.Length > 0)
{
ExecutionMethod.CommandLine = true;
ProcessCommandLineArgs.ProcessArgs(e.Args);
base.Shutdown();
}
else
{
FreeConsole();
ExecutionMethod.CommandLine = false;
TestApp WindowToDisplay = new TestApp();
WindowToDisplay.Show();
}
}
}
I am able to process the arguments and display the result on console.
But the issues is
This TestApp, creates process, say P1 , which execute some commands and result gets re-directed to console output. Before P1 completes, main process exited due to base.Shutdown() in above overridden method.
How I can make this base.shutdown to wait for Process P1 to finish.
Any link/suggestions
Regards