使用SetConsoleMode
清除ENABLE_QUICK_EDIT_MODE
模式。当您的程序退出时,恢复标志到其先前的设置是礼貌的。
由于该问题没有直接的解决方案,因此采用以下解决方法进行修复:
string filelocation = Assembly.GetExecutingAssembly().Location;
string filename = Process.GetCurrentProcess().MainModule.ModuleName;
filename = filename.Replace(".exe", "");
Process[] processArray = Process.GetProcesses();
int processesExists = 0;
for (int i2 = 0; i2 < (processArray.Length - 1); i2++)
{
if (processArray[i2].ProcessName.Contains(filename))
{
processesExists++;
}
}
if (processesExists == 1 && !Console.Title.Contains("cmd"))
{
Process.Start("cmd.exe", "/C " + "\"" + filelocation + "\"");
}
if (!Console.Title.Contains("cmd"))
{
Process.GetCurrentProcess().Kill();
}