wpf-控制台程序

c#建立的控制台程序运行时如何不弹出DOS窗口

// 创建好控制台程序后,选中项目,右键,属性,输出类型选为“windows 应用程序” 这样就没有dos窗口了。

单例模式

var curId = System.Diagnostics.Process.GetCurrentProcess().Id;

bool isAppRunning = false;
var name = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
System.Threading.Mutex mutex = new System.Threading.Mutex(true, name, out isAppRunning);
if (!isAppRunning)
{
Log.Warning("already running. kill the running one.");
foreach (var process in Process.GetProcessesByName(name))
{
if (process.Id != curId)
{
process.Kill();
}
}
}