【发布时间】:2020-10-25 21:24:55
【问题描述】:
我想结束一个使用 ProcessStartInfo 启动的进程,这是启动它的代码
public class MyProcess
{
void OpenWithStartInfo()
{
ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe");
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = true;
startInfo.FileName = "C:/StartBot.bat";
Process.Start(startInfo);
}
public static void Start()
{
MyProcess myProcess = new MyProcess();
myProcess.OpenWithStartInfo();
}
public static void End()
{
}
}
我想结束我使用 End() 函数开始的过程,但我不知道该怎么做。任何帮助将不胜感激。
【问题讨论】:
-
1) 看这篇文章,如何异步启动进程:Is there any async equivalent of Process.Start?。 2)以及如何停止进程的以下帖子:How can I stop async Process by CancellationToken?
-
这能回答你的问题吗? How do I kill a process using Vb.NET or C#?