在wpf应用程序中使用process.start来调用另一个wpf应用程序

San*_*ana 8 c# wpf process calling-convention argument-passing

我试图从另一个wpf应用程序调用一个wpf应用程序.调用wpf应用程序进行调用

ProcessStartInfo BOM = new ProcessStartInfo();

BOM.FileName = @"D:\WPFAPPLICATION.exe";

BOM.Arguments = temp;

Process.Start(BOM);
Run Code Online (Sandbox Code Playgroud)

现在在调用的应用程序中,我尝试检索传递的参数

  string arguments =Process.GetCurrentProcess().StartInfo.Arguments;
Run Code Online (Sandbox Code Playgroud)

但是参数没有通过.为什么是这样??

我还尝试了一种替代方法,其中:

    public partial class App : Application
    {
    public static String[] mArgs;

    private void Application_Startup(object sender, StartupEventArgs e)
    {

        if (e.Args.Length > 0)
        {
            mArgs = e.Args;


        }
    }
    }
    }
Run Code Online (Sandbox Code Playgroud)

然而,这也不起作用!请帮忙!!

San*_*ana 2

好吧,如果有人感兴趣的话,我终于找到了我的问题的解决方案。在调用应用程序时,我维护了之前使用的相同代码:

ProcessStartInfo BOM = new ProcessStartInfo();
BOM.FileName = @"D:\WPFAPPLICATION.exe";
BOM.Arguments = temp;
Process.Start(BOM);
Run Code Online (Sandbox Code Playgroud)

在被调用的应用程序中,为了成功接收参数,我只需:

    System.Text.StringBuilder strbuilder= new System.Text.StringBuilder();


    foreach (String arg in Environment.GetCommandLineArgs())
    {
        strbuilder.AppendLine(arg);
        barcode = arg;
    }
    psnfo = strbuilder.ToString();
Run Code Online (Sandbox Code Playgroud)

我没有以正确的方式处理传递给进程的参数

所以在显示 psnfo 时

代码返回:

 D:\WPFAPPLICATION.exe temp
Run Code Online (Sandbox Code Playgroud)

来源:http ://www.codeproject.com/Questions/386260/Using-process-start-in-a-wpf-application-to-invoke