/// <summary> /// 开始运行服务 /// </summary> /// <param name="args">args</param> /// <param name="serviceName">服务名</param> /// <param name="serviceInit">服务初始化</param> public static void StarUpService(string args, string serviceName, ServiceInit serviceInit) { if (args == "0") { //运行在console方式下 serviceInit.Start(); } else if (args == "1") { //运行在windows服务方式下 ServiceBase.Run(new ServiceRun(serviceInit, serviceName)); } else { Debug.Assert(false); //运行在windows服务方式下 ServiceBase.Run(new ServiceRun(serviceInit, serviceName)); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="init">服务初始化类</param> /// <param name="Name">服务的名字</param> public ServiceRun(ServiceInit init, string Name) { this.SmcInit = init; this.InitializeComponent(Name); }