在一个应用程序A中启动另一个应用程序B,要把A中的参数stringItem传给B,在B的一个textbox中显示。我用Process.Start(senderLocation, stringItem);启动B并传值。请问如何在B中接收这个参数stringItem呢?

解决方案 »

  1.   

    分布式编程
    利用Tcp 或者 Http通道来传递远程对象
      

  2.   

    具体应该怎么做呢?能给出代码吗?
    这个应该很简单吧。网上有类似问题,不同应用程序都是用Process.Start(yourApp)来启动。
    传递参数的话只要用Process.Start(yourApp,parameter)来启动,但是没有说明在yourApp应用程序中如何使用parameter这个参数。
      

  3.   

     1private void runSyncAndGetResults_Click(object sender, System.EventArgs e)
     2{
     3    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:\listfiles.bat"); 
     4    psi.RedirectStandardOutput = true; 
     5    psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 
     6    psi.UseShellExecute = false; 
     7    System.Diagnostics.Process listFiles; 
     8    listFiles = System.Diagnostics.Process.Start(psi); 
     9    System.IO.StreamReader myOutput = listFiles.StandardOutput; 
    10    listFiles.WaitForExit(2000);
    11    
    12    if (listFiles.HasExited)  
    13    {  
    14        string output = myOutput.ReadToEnd();  
    15        this.processResults.Text = output; 
    16    }
    17}
    第二个程序是个控制台程序,
    输出在控制台上显示的字符串.
      

  4.   

     1private void runSyncAndGetResults_Click(object sender, System.EventArgs e)
     2{
     3    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:\listfiles.bat"); 
     4    psi.RedirectStandardOutput = true; 
     5    psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 
     6    psi.UseShellExecute = false; 
     7    System.Diagnostics.Process listFiles; 
     8    listFiles = System.Diagnostics.Process.Start(psi); 
     9    System.IO.StreamReader myOutput = listFiles.StandardOutput; 
    10    listFiles.WaitForExit(2000);
    11    
    12    if (listFiles.HasExited)  
    13    {  
    14        string output = myOutput.ReadToEnd();  
    15        this.processResults.Text = output; 
    16    }
    17}
    主义,这个例子里面的被启动的
      

  5.   

    .net Remoting是可以的
    google一些资料看看吧
      

  6.   

    我在A进程中用Process.Start(yourApp,parameter)来启动进程B后,在B进程里用ProcessStartInfo psi = new ProcessStartInfo();
              string senderLocation = psi.Arguments;为什么无法得到传进来的parameter参数?我还是想用Process.Start(yourApp,parameter)来传参数,这样可以在我原来代码的基础上改动最少。大家说说看呢。
      

  7.   


    在B程序中,找到static void Main(), 然后稍加改动即可:
            static void Main(String[] args)                 // <---------加String[] args
            {
                //...
                MessageBox.Show(string.Join("\n", args));   // <---------加一行显示
                Application.Run(new Form1());
            }