天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

79 lines
2.2 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace QMHTIS.Host
{
public delegate bool ConsoleCtrlDelegate(int CtrlType);
class Program
{
[DllImport("kernel32.dll")]
private static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate HandlerRoutine, bool Add);
static ConsoleCtrlDelegate consoleCtrl = new ConsoleCtrlDelegate(HandlerRoutine);
/// <summary>
/// 程序关闭事件
/// </summary>
/// <param name="ctrlType"></param>
/// <returns></returns>
public static bool HandlerRoutine(int ctrlType)
{
switch (ctrlType)
{
case 0:
case 2:
Console.WriteLine("控制台关闭");
//停止服务
_manager.Stop();
break;
default:
break;
}
return false;
}
/// <summary>
/// 服务管理者
/// </summary>
private static ServiceManager _manager = null;
static void Main(string[] args)
{
bool bRet = SetConsoleCtrlHandler(consoleCtrl, true);
try
{
QMFrameWork.Log.LogManager.Configure("log4net");
//装配数据工厂
QMFrameWork.Data.DataFactory.Configure(true);
//定义服务管理者
_manager = new ServiceManager();
//启动服务
_manager.Start();
Console.ReadLine();
//停止服务
//_manager.Stop();
}
catch (Exception ex)
{
if (QMFrameWork.Log.LogManager.LogHelper != null)
{
QMFrameWork.Log.LogManager.LogHelper.Error(
new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "应用启动", ErrorInfo = ex });
}
//停止服务
_manager.Stop();
Console.WriteLine(ex.Message);
}
}
}
}