次のコードで新しいプロセスを作成しようとしているとしましょう。
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
p.StartInfo.FileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\AwesomeFile.exe";
p.StartInfo.Arguments = "parameter1 parameter2";
p.StartInfo.CreateNoWindow = true;
p.Start();
次の行で、次の行を使用してそのプロセスのpidを取得しようとします。
MessageBox.Show(p.Id);
この行は、「このオブジェクトに関連付けられているプロセスはありません」と表示しています。エラー。このエラーが発生する理由について何か考えはありますか?