C#怎样在开启线程时将控制台隐藏
答案:1 悬赏:50 手机版
解决时间 2021-01-03 03:30
- 提问者网友:雪舞兮
- 2021-01-03 00:22
写了个简易管理端,服务器,客户端,管理客户端都会向服务器发送接收消息,服务器一直运行,因为是用控制台写的,所以想把控制台隐藏
最佳答案
- 五星知识达人网友:逐風
- 2021-01-03 00:56
或许你需要调用WINDOWS API才可以实现,代码如下:
class Program
{
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();// 获取控制台句柄
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_HIDE = 0;// 隐藏
const int SW_SHOW = 5;// 显示
static void Main(string[] args)
{
Console.WriteLine("3秒后立即隐藏...");
System.Threading.Thread.Sleep(3000);
ShowWindow(GetConsoleWindow(), SW_HIDE);// 隐藏
Console.ReadKey(true);
}
}
class Program
{
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();// 获取控制台句柄
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_HIDE = 0;// 隐藏
const int SW_SHOW = 5;// 显示
static void Main(string[] args)
{
Console.WriteLine("3秒后立即隐藏...");
System.Threading.Thread.Sleep(3000);
ShowWindow(GetConsoleWindow(), SW_HIDE);// 隐藏
Console.ReadKey(true);
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯