手动关闭一个进程后如何关闭另一个进程?
How do I close a process once I manually shut down another?
我只是想制作一个控制台应用程序来使用工具启动我的游戏(该工具可以帮助游戏解决它存在的一些错误)。
完成游戏后,我想通过游戏内菜单关闭游戏,然后我希望它随工具一起关闭,而无需手动将其关闭。
不过我似乎无法让它正常工作,如果我使用 "flawlessWideScreen.Close();",该工具会在我的游戏关闭后保持打开状态,如果我使用 "flawlessWideScreen.Kill();",它会抛出异常。
有人知道我做错了什么吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
namespace Bioshock2AdvancedLauncher
{
class Program
{
static void Main(string[] args)
{
ProcessStartInfo bioshock2Info = new ProcessStartInfo();
bioshock2Info.FileName = (@"F:\Steam Library\steamapps\common\BioShock 2\SP\Builds\Binaries\Bioshock2.exe");
bioshock2Info.WorkingDirectory = Path.GetDirectoryName(@"F:\Steam Library\steamapps\common\BioShock 2\SP\Builds\Binaries\Bioshock2.exe");
Process bioshock2 = new Process();
bioshock2.EnableRaisingEvents = true;
bioshock2 = Process.Start(bioshock2Info);
Process flawlessWideScreen = new Process();
flawlessWideScreen = Process.Start(@"F:\Steam Library\steamapps\common\BioShock 2\SP\Builds\Binaries\FlawlessWidescreen.lnk");
bioshock2.WaitForExit();
flawlessWideScreen.Kill();
}
}
}
我通过替换 flawlessWideScreen.Kill() 修复了它;使用此代码。
foreach (Process p in Process.GetProcesses())
{
string name = p.ProcessName.ToLower();
if (name == "flawlesswidescreen") p.Kill();
}
我只是想制作一个控制台应用程序来使用工具启动我的游戏(该工具可以帮助游戏解决它存在的一些错误)。 完成游戏后,我想通过游戏内菜单关闭游戏,然后我希望它随工具一起关闭,而无需手动将其关闭。 不过我似乎无法让它正常工作,如果我使用 "flawlessWideScreen.Close();",该工具会在我的游戏关闭后保持打开状态,如果我使用 "flawlessWideScreen.Kill();",它会抛出异常。
有人知道我做错了什么吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
namespace Bioshock2AdvancedLauncher
{
class Program
{
static void Main(string[] args)
{
ProcessStartInfo bioshock2Info = new ProcessStartInfo();
bioshock2Info.FileName = (@"F:\Steam Library\steamapps\common\BioShock 2\SP\Builds\Binaries\Bioshock2.exe");
bioshock2Info.WorkingDirectory = Path.GetDirectoryName(@"F:\Steam Library\steamapps\common\BioShock 2\SP\Builds\Binaries\Bioshock2.exe");
Process bioshock2 = new Process();
bioshock2.EnableRaisingEvents = true;
bioshock2 = Process.Start(bioshock2Info);
Process flawlessWideScreen = new Process();
flawlessWideScreen = Process.Start(@"F:\Steam Library\steamapps\common\BioShock 2\SP\Builds\Binaries\FlawlessWidescreen.lnk");
bioshock2.WaitForExit();
flawlessWideScreen.Kill();
}
}
}
我通过替换 flawlessWideScreen.Kill() 修复了它;使用此代码。
foreach (Process p in Process.GetProcesses())
{
string name = p.ProcessName.ToLower();
if (name == "flawlesswidescreen") p.Kill();
}