⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codemanageservice.cs

📁 自定义协议
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;

namespace CodeManagerService
{
	public class CodeManageService : System.ServiceProcess.ServiceBase
	{
		/// <summary> 
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public CodeManageService()
		{
			// 该调用是 Windows.Forms 组件设计器所必需的。
			InitializeComponent();

			// TODO: 在 InitComponent 调用后添加任何初始化
		}

		// 进程的主入口点
		static void Main()
		{
			System.ServiceProcess.ServiceBase[] ServicesToRun;
	
			// 同一进程中可以运行多个用户服务。若要将
			//另一个服务添加到此进程,请更改下行
			// 以创建另一个服务对象。例如,
			//
			//   ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
			//
			ServicesToRun = new System.ServiceProcess.ServiceBase[] { new CodeManageService() };

			System.ServiceProcess.ServiceBase.Run(ServicesToRun);
		}

		/// <summary> 
		/// 设计器支持所需的方法 - 不要使用代码编辑器 
		/// 修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			// 
			// CodeManageService
			// 
			this.CanHandlePowerEvent = true;
			this.CanPauseAndContinue = true;
			this.CanShutdown = true;
			this.ServiceName = "CodeManageService";

		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		/// <summary>
		/// 设置具体的操作,以便服务可以执行它的工作。
		/// </summary>
		protected override void OnStart(string[] args)
		{
			// TODO: 在此处添加代码以启动服务。
			System.Threading.ThreadStart myThreadDelegate1 = new System.Threading.ThreadStart( CSock_Info.start );
			System.Threading.Thread oThread1 = new System.Threading.Thread( myThreadDelegate1 );
			oThread1.IsBackground = true;
			oThread1.Start();

			System.Threading.ThreadStart myThreadDelegate2 = new System.Threading.ThreadStart( CSock_File.start );
			System.Threading.Thread oThread2 = new System.Threading.Thread( myThreadDelegate2 );
			oThread2.IsBackground = true;
			oThread2.Start();

		}
 
		/// <summary>
		/// 停止此服务。
		/// </summary>
		protected override void OnStop()
		{
			// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
			CSock_Info.stop();
			CSock_File.stop();
			System.GC.Collect();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -