.NET控制台程序监听程序退出
There are mainly 2 types of Win32 applications, console application and window application. They have different way in handling application exit. To force Window application to exit, you need to send out WM_CLOSE message to the main window handle. That's pretty simple to handle. You can hook up to Application.ApplicationExit or Form.Close at the form level. However, in a console application, it is a little bit different. Console applications are somehow modeled after DOS console application where usually an application exits when stdin is dead or Ctrl+C is pressed. To handle this properly in C#, you can set a delegate to SetConsoleCtrlHandler.You will have an opportunity to clean up resource or finish your work before the application actually exits.
// Declare the SetConsoleCtrlHandler function
// as external and receiving a delegate. [DllImport("Kernel32")]
public static extern bool SetConsoleCtrlHandler(HandlerRoutine Handler, bool Add); // A delegate type to be used as the handler routine
// for SetConsoleCtrlHandler.
public delegate bool HandlerRoutine(CtrlTypes CtrlType); // An enumerated type for the control messages
// sent to the handler routine.
public enum CtrlTypes
{
CTRL_C_EVENT = 0,
CTRL_BREAK_EVENT,
CTRL_CLOSE_EVENT,
CTRL_LOGOFF_EVENT = 5,
CTRL_SHUTDOWN_EVENT
} private static bool ConsoleCtrlCheck(CtrlTypes ctrlType)
{
// Put your own handler here
return true;
} ... SetConsoleCtrlHandler(new HandlerRoutine(ConsoleCtrlCheck), true);
.NET控制台程序监听程序退出的更多相关文章
- 免Oracle客户端程序监听程序配置
Oracle默认安装时,监听程序和tnsnames程序中的监听方式都是默认的localhost,但免客户端的程序是连接不上的.这时需要: 1.将listener中的(HOST = localhost) ...
- 安装完oracle重新启动后报ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务(重启前正常)
安装完oracle重新启动后报ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务(重启前正常) 刚安装完后用plSql登录正常. 在dos命令行下 输入 sqlplus 用户 ...
- lsnrctl start 命令未找到 数据库连接报错“ORA-12541: TNS: 无监听程序”
1. lsnrctl start 命令未找到 或者bash:lsnrctl:command not found. su - oralce 切换用户的时候,中间要有-,而且-的两边有空格, ...
- Oracle ORA-12541:TNS:无监听程序
Oracle ORA-12541:TNS:无监听程序 标签: Oracle DataBase 今天使用Oracle数据库,使用可视化连接工具连接测试环境的数据库时提示无监听程序,最后在老师帮助下终于搞 ...
- 一个基于Socket的http请求监听程序实现
首先来看以下我们的需求: 用java编写一个监听程序,监听指定的端口,通过浏览器如http://localhost:7777来访问时,可以把请求到的内容记录下来,记录可以存文件,sqlit,mysql ...
- 解决windows7无法连接CentOS7系统中oracle问题:ORA-12514 TNS 监听程序当前无法识别
linux开启后终端按下面输入(容易忘记,记录下): [oracle@localhost ~]$ lsnrctl stop #先关闭监听服务 [oracle@localh ...
- Linux下启动Oracle服务和监听程序步骤
Linux下启动Oracle服务和监听程序启动和关闭步骤整理如下: 1.安装oracle: 2.创建oracle系统用户: 3./home/oracle下面的.bash_profile添加几个环境变量 ...
- 2018.5.6 解决问题:oracle------ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务
解决问题:ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 或者是重启电脑之后无法进入控制台企业管理器(OEM)图形化界面(重新添加注入监听器就行了 文件listener.org) ...
- (转)ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法
早上同事用PL/SQL连接虚拟机中的Oracle数据库,发现又报了"ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务"错误,帮其解决后,发现很多人遇到过这样的问 ...
随机推荐
- java打成jar包后,class,getResource()出现null指针异常
1.SqlHelper.java有包路径没?如果有,是不是类似于com.db.jdbc? 不管怎么办,你SqlHelper.class.getResourceAsStream("/mysql ...
- Fiddler系统监控参数解读
转自:https://blog.csdn.net/txj236/article/details/38872855 在对系统监控的过程中,发现ClientConnected和ClientBeginReq ...
- [转]Passing Managed Structures With Strings To Unmanaged Code Part 1
1. Introduction. 1.1 Managed structures that contain strings are a common sight. The trouble is that ...
- 控制某个panel的display样式
"我想在onload方法里把panel的 style 里的 display 属性变成 none.我的页面由于有一些脚本,触发某些事件之后还想显示这个panel,不想用Panel3.Visib ...
- Transfer data to SQL Server from SPC-Light with Excel macros
公司的QA检测软件SPC-Light,需要从其中读取一些信息至SQL Server数据库,储存或是做其它分析. 先是在Excel的VBE的工具中,引入一个组件Microsoft ActiveX Dat ...
- python---信用卡ATM
一 需求 模拟实现一个ATM + 购物商城程序 额度 15000或自定义 实现购物商城,买东西加入 购物车,调用信用卡接口结账 可以提现,手续费5% 每月22号出账单,每月10号为还款日,过期未还, ...
- myql 服务启动不了怎么办
今天,不小心手动将mysql 服务停掉后,怎么也启动不了,后面查了半天 ,终于知道要先将任务管理器里的mysql.exe 先Kill掉,然后可以启动了,记录一下
- RGB颜色表-网址不见了看这里
英文不翻译 翻译成中文
- php二维数组的某一字段 做分组统计
$country=array_column($order,'country');$countryGP=array_count_values($country);对二维数组的某一字段 做分组统计
- loj #2007. 「SCOI2015」国旗计划
#2007. 「SCOI2015」国旗计划 题目描述 A 国正在开展一项伟大的计划 —— 国旗计划.这项计划的内容是边防战士手举国旗环绕边境线奔袭一圈.这项计划需要多名边防战士以接力的形式共同完成 ...