dos下运行c#程序时,点击右上角关闭的那个X 我在dos下运行一个c#程序,在对数据库进行一连串的插入操作的时候,如果中途点击关闭dos窗口,则必须把之前插入到数据库的数据全部清空请问该如何实现,c#中有没监听程序异常中止的监听器 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 恩 是的 。。运行 XXX.exe +参数 我在网上帮你查找了下 有人解决的 人家是用windows API才捕捉消息来实现代码如下 测试通过 顺便学习下using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.InteropServices;using System.Diagnostics;namespace ConsoleApplication17{ public delegate bool ConsoleCtrlDelegate(int dwCtrlType); class Program { [DllImport("kernel32.dll")] private static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate HandlerRoutine, bool Add); //当用户关闭Console时,系统会发送次消息 private const int CTRL_CLOSE_EVENT = 2; static void Main(string[] args) { Program mc = new Program(); Console.ReadLine(); } public Program() { // 用API安装事件处理 ConsoleCtrlDelegate newDelegate = new ConsoleCtrlDelegate(HandlerRoutine); bool bRet = SetConsoleCtrlHandler(newDelegate, true); if (bRet == false) //安装事件处理失败 { Debug.WriteLine("失败"); } else { Console.WriteLine("ok"); Console.Read(); } } /// <summary> /// 处理消息的事件 /// </summary> private static bool HandlerRoutine(int CtrlType) { switch (CtrlType) { case CTRL_CLOSE_EVENT: //用户要关闭Console了 Debug.WriteLine("Close"); break; } return false; } }} 要5个小时? 事先的文本文件为什么就不能改成csv,excel什么的 直接在程序里操作excel数据 要快的多 新手问题~问下如何个ComboBox设置value. Visual C#绘图 请问vs2005写的程序能在vs2008下运行么? listview 点击某一行 如何得到该行某一列的值?? 散分:欢迎大家来讨论 datagrid导出到Excel中的问题 C#如何编程来取得某些带COOKIES认证的论坛网页的内容 怎么把datagridview添加的数据库源删除?如图,求解 vs2005(c#)+sql server2005开发WINFORM数据库管理系统的报表打印问题 在ASP,NET中,数据库怎样用MD5加密密码,求代码和运用方法 .NET问题 帮忙解决下 我想问各位大侠一个实现方法
代码如下 测试通过
顺便学习下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;namespace ConsoleApplication17
{ public delegate bool ConsoleCtrlDelegate(int dwCtrlType);
class Program
{
[DllImport("kernel32.dll")]
private static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate HandlerRoutine, bool Add);
//当用户关闭Console时,系统会发送次消息
private const int CTRL_CLOSE_EVENT = 2;
static void Main(string[] args)
{
Program mc = new Program();
Console.ReadLine();
} public Program()
{
// 用API安装事件处理
ConsoleCtrlDelegate newDelegate = new ConsoleCtrlDelegate(HandlerRoutine);
bool bRet = SetConsoleCtrlHandler(newDelegate, true);
if (bRet == false) //安装事件处理失败
{
Debug.WriteLine("失败");
}
else
{
Console.WriteLine("ok");
Console.Read();
}
}
/// <summary>
/// 处理消息的事件
/// </summary>
private static bool HandlerRoutine(int CtrlType)
{
switch (CtrlType)
{
case CTRL_CLOSE_EVENT: //用户要关闭Console了
Debug.WriteLine("Close");
break;
} return false;
}
}
}