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