Reputation: 1020
Process.Start(jrekeypath);
Thread.Sleep(5);
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.StartsWith("javaw"))
{
clsProcess.Kill();
}
}
It doesn't kill the process. Is there any problem in this snippet?
Upvotes: 2
Views: 539
Reputation: 34408
Ditto the 5ms answer above, but you could also try keeping the process handle around and re-using that, e.g.
var javawProcess = Process.Start(jrekeypath);
Thread.Sleep(5000);
javawProcess.Kill();
Upvotes: 10
Reputation: 158289
5 ms is not an extremely long time. Could it be that the process has in fact not yet started when your code looks for it, but instead starts shortly afterwards?
Upvotes: 5