feat: -console argument

This commit is contained in:
ChsBuffer
2020-10-10 22:37:23 +08:00
parent 406fbd8b7e
commit 45b6352553
2 changed files with 13 additions and 0 deletions

View File

@@ -66,5 +66,11 @@ namespace Netch
[DllImport("dnsapi", EntryPoint = "DnsFlushResolverCache")]
public static extern uint FlushDNSResolverCache();
[DllImport("kernel32.dll")]
public static extern bool AllocConsole();
[DllImport("kernel32.dll")]
public static extern bool AttachConsole(int dwProcessId);
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -17,6 +18,12 @@ namespace Netch
[STAThread]
public static void Main(string[] args)
{
if (args.Contains("-console"))
{
NativeMethods.AllocConsole();
NativeMethods.AttachConsole(-1);
}
// 创建互斥体防止多次运行
using (var mutex = new Mutex(false, "Global\\Netch"))
{