Using AttachConsole, user must hit enter to get regular command line(使用 AttachConsole,用户必须按 Enter 才能获得常规命令行)
问题描述
我有一个程序,既可以作为 winform 运行,也可以从命令行运行.如果它是从命令行调用的,我会调用 AttachConsole(-1) 来附加到父控制台.
I have a progaram that can be ran both as a winform, or from command line. If it is invoked from a command line I call AttachConsole(-1) to attach to parent console.
但是,在我的程序结束后,用户必须按回车键才能返回标准命令提示符(c:>").有没有办法避免这种需要?
However, after my program ends, the user must hit enter to get back the standard command prompt ("c:>"). is there a way to avoid that need?
谢谢.我可以将它包装在一个 cmd 文件中以避免该问题,但我想从我的 exe 中完成.
Thanks. I could wrap it in a cmd file to avoid that issue, but I would like to do it from my exe.
推荐答案
尝试在你的 exe 退出前添加这一行...
Try adding this line just before your exe exits...
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
有点小技巧,但是当我遇到这个问题时,我能找到最好的方法.
Bit of a hack, but best I could find when I encountered that problem.
这篇关于使用 AttachConsole,用户必须按 Enter 才能获得常规命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 AttachConsole,用户必须按 Enter 才能获得常规命令行
基础教程推荐
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 如果条件可以为空 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 将数据集转换为列表 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
