且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何在运行程序后运行方法

更新时间:2023-01-15 20:30:07

奇怪的请求,但最简单的方法是通过设置
Odd sort of request, but the easiest way is to pass an argument to the Process.Start by setting the
ProcessStartInfo.Arguments property:
ProcessStartInfo Info = new ProcessStartInfo();
Info.Arguments = "/C ping 127.0.0.1 -n 10 && \"" + Application.ExecutablePath + "\"";
Info.WindowStyle = ProcessWindowStyle.Hidden;
Info.CreateNoWindow = true;
Info.FileName = "cmd.exe";
info.Arguments = @"/AutoRun";
Process.Start(Info);
Application.Exit();



然后,您可以检查您的应用程序参数作为主Form构造函数的一部分:


You can then check your application arguments as part of the main Form constructor:

string[] args = Environment.GetCommandLineArgs();
if (args.Length > 1 && args[1] == @"/AutoRun")
  {
  // Run your method
  }