123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.ServiceProcess;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- using System.Threading;
- using System.Management;
- namespace LYFZ.WcfSystemService
- {
- /// <summary>
- /// 查看其各属性的含意是:
- /// Autolog 是否自动写入系统的日志文件
- /// CanHandlePowerEvent 服务时候接受电源事件
- /// CanPauseAndContinue 服务是否接受暂停或继续运行的请求
- /// CanShutdown 服务是否在运行它的计算机关闭时收到通知,以便能够调用 OnShutDown 过程
- /// CanStop 服务是否接受停止运行的请求
- /// ServiceName 服务名
- /// </summary>
- public partial class LYFZ_ErpWcfService : ServiceBase
- {
- private LYFZ.WindowsServiceHandling.MainService mainService = new LYFZ.WindowsServiceHandling.MainService();
- public LYFZ_ErpWcfService()
- {
- InitializeComponent();
- // SetTimerRunWork();//执行定时任务
- mainService.InitializeConstructor();
-
- }
- /// <summary>
- /// windows服务是不执行Timer控件的,解决办法
- /// </summary>
- protected void SetTimerRunWork()
- {
- System.Timers.Timer t = new System.Timers.Timer();
- t.Interval = 1000 * 10;
- t.Elapsed += new System.Timers.ElapsedEventHandler(RunWork);
- t.AutoReset = true;//设置是执行一次(false),还是一直执行(true);
- t.Enabled = true;//是否执行
- }
- public void RunWork(object source, System.Timers.ElapsedEventArgs e)
- {
- //要定时处理的事情
- //这样服务就可以定时执行任务了
- ServiceWriteLog("定时任务正在执行...");
- }
- /// <summary>
- /// 写服务日志
- /// </summary>
- /// <param name="txt"></param>
- protected void ServiceWriteLog(string txt)
- {
-
- }
- /// <summary>
- /// 开始
- /// </summary>
- /// <param name="args"></param>
- protected override void OnStart(string[] args)
- {
- // ServiceWriteLog("服务器启动成功.");
- mainService.OnStart(args);
- }
- /// <summary>
- /// 停止
- /// </summary>
- protected override void OnStop()
- {
- mainService.OnStop();
- // ServiceWriteLog("服务器已停止.");
- }
- /// <summary>
- /// 暂停
- /// </summary>
- protected override void OnPause()
- {
- mainService.OnPause();
- }
- /// <summary>
- /// 继续
- /// </summary>
- protected override void OnContinue()
- {
- mainService.OnContinue();
- }
- /// <summary>
- /// 计算机关闭时
- /// </summary>
- protected override void OnShutdown() {
- mainService.OnShutdown();
- }
- }
- }
|