Assume you are starting the process with the code shown below. Then immediately after the start you would like to perform any operation on the retrieved process instance.
In my example I start the process and kill it after 5 seconds.
Process proc = new
Process();
proc.StartInfo.Arguments = "wf";
proc.StartInfo.FileName = Assembly.GetExecutingAssembly().CodeBase;
proc.Start();
Thread.Sleep(5000);
proc.Kill();
If you run this code on windows Vista all works fine. However, if you run this code on the previous version of windows (i.E.) WindowsXP, this code will fail, when kill method is invoked. The reasons is not that kill method does not work well. The problem is that the instance of the process is invalid after starting of the process. To work around the problem try this code:
Process proc = new
Process();
proc.StartInfo.Arguments = "wf";
proc.StartInfo.FileName = @"D:/Tests/Daenet.WF.SafePersistance.exe";
proc.Start();
Thread.Sleep(5000);
proc.Kill();
Difference here is that the path of the executable is explicitly given. Note that path in the previous example would look like: "file:///D:/Tests/Daenet.WF.SafePersistance.exe";". This kind of path can obviously be solved by Windows Vista.
Posted
Nov 16 2007, 10:38 AM
by
Damir Dobric