- 调用方的程序调用代码:
Process.Start(string exePathAndName, string parameter);
- 被调用 方 接收参数
1)可以在项目的入口程序program.cs 的
[STAThread]
static void Main(string[] msg)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Client_Maintenance());
//******msg 就是传过来的参数
Application.Run(new Login());
}
2) 也可以在项目的启动文件,例如 login 等.
在PageLoad 事件中:
string[] args = Environment.GetCommandLineArgs();
if (args.Length > 1)
{
txtLoginName.Text = (args[1].toString()); 注意是: args[1]
}
3.其它 . 还可以得到被调用方Main方法返回的值
private void button1_Click(object sender, EventArgs e)
{
Process da = new Process();
da.StartInfo.FileName = “ConsoleApplicationTest.exe”;
da.StartInfo.UseShellExecute = false;
da.StartInfo.RedirectStandardInput = true;
da.StartInfo.RedirectStandardOutput = true;
da.StartInfo.RedirectStandardError = true;
da.StartInfo.CreateNoWindow = true;
da.Start();
da.WaitForExit();//等待对方退出
int nn = da.ExitCode; //得到返回值
da.Close();
MessageBox.Show(nn.tostring());
}