问题
We are using this code to launch a Wpf form:
string fileName = @"C:\Test\bin\Debug\WpfTest.exe";
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(fileName);
psi.Arguments = entryZfName;
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
The WpfTest is an appliation which contain a WPFForm1.xaml which gets launched. How to access the arguments in this form that were set to psi in the above code. Are they accessible in the constructor? Also how to debug this scenario, in other words since i am launching the wpftest.exe directly from the code i am not able to debug or access the code, is it possible to debug this. Let me know if you need more info
回答1:
you can use Environment.GetCommandLineArgs to get args. To Debug you can add Debug.Launch() in the wpf form or the place you want to start debugging if you have access to the code..
回答2:
You can get your command line args from Environment.GetCommandLineArgs, or from the constructor as you have noted.
You can debug the process by opening up its solution in Visual Studio, going to the Debug menu, and choosing "Attach to Process". You can then attach to WpfTest.exe and debug it as if you had started it from Visual Studio.
来源:https://stackoverflow.com/questions/2245568/figure-the-arguments-when-wpf-form-is-started-using-process-class