There is a WPF application, from which you need to launch another small WPF application as an executable file (.exe) with parameters passed from their main application. And at the start of the second application, a check occurs, if there are no parameters, then another window starts, where it is necessary to enter them manually. I do this in the App file:

public string[] Parameters { get; set; } protected override void OnStartup(StartupEventArgs e) { Parameters = e.Args; base.OnStartup(e); } 

in the main application window:

  public string Medicament { get; set; } public float Concentration { get; set; } public float SpecGravity { get; set; } public MainWindow() { var parameters = ((App)Application.Current).Parameters; SetParameters(parameters); InitializeComponent(); DataContext = this; TextBoxMg.Focus(); } private void SetParameters(string[] parameters) { if (parameters.Length > 0) { Medicament = parameters[0]; if (parameters.Length >= 2) SpecGravity = Convert.ToSingle(parameters[1]); else ShowParametersView(); if (parameters.Length >= 3) Concentration = Convert.ToSingle(parameters[2]); else ShowParametersView(); } else ShowParametersView(); } private void ShowParametersView() { var parametersView = new ParametersView { Medicament = Medicament, SpecGravity = SpecGravity, Concentration = Concentration }; parametersView.ShowDialog(); Medicament = parametersView.Medicament; SpecGravity = parametersView.SpecGravity; Concentration = parametersView.Concentration; } 

The problem is that the second application starts and closes immediately. As far as I could determine, this happens due to the setting of parameters. If in the constructor instead of calling the SetParameters() method, immediately ShowParametersView() , then everything works fine.

What am I doing wrong?

PS From the console application runs without problems, it also works under the debugger with parameters

  • one
    Well, you never know what, maybe an exception is thrown. Try to launch the second application not from the first, but from under the debugger and give it the same command line parameters. - VladD
  • I forgot to write. Tried of course different options. From under the debugger, it runs without problems, from the console application, too, without problems. - S_Schmal
  • Ok, this is more interesting. Then maybe you incorrectly pass the parameters. Try starting the second application to drop the parameters into a text file, one per line. - VladD
  • Is this to be done in App.cs? - S_Schmal
  • one
    If there are spaces in the parameter, it must be enclosed in "quotes" in order for the arguments to come as they should. - Monk

0