Figure the arguments when wpf form is started using Process Class

。_饼干妹妹 提交于 2019-12-11 14:57:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!