zoukankan      html  css  js  c++  java
  • window service 插件服务插件开发

    1、新建一个Window类库项目,如下图所示:

    image

    2、添加插件接口引用:

    image

    3、引用命名空间

    image

    4、TimeLogPlug类实现接口IService

    image

    5、在类上加入属性定义:

    image

    6、完整实现类如下:

       1: using System;
       2: using System.Collections.Generic;
       3: using System.Text;
       4:  
       5: using WindowServices.Interface;
       6: using System.ComponentModel;
       7:  
       8: namespace TimeLog
       9: {
      10:     [DisplayName("时间日志服务")]
      11:     [Description("每10秒写入日志文件一个时间。")]
      12:     [System.Runtime.InteropServices.Guid("2301DE7F-22A0-415E-9E35-0BE71BD62C76")]
      13:     [Serializable]
      14:     public class TimeLogPlug:IService
      15:     {
      16:         private ServiceEntity _serviceEntity;
      17:         private bool _isRuning;
      18:         public void Initialize(ServiceEntity serviceEntity)
      19:         {
      20:             _serviceEntity = serviceEntity;
      21:         }
      22:  
      23:         public void Pause()
      24:         {
      25:         }
      26:  
      27:         public void Start()
      28:         {
      29:             _isRuning = true;
      30:             using (var sw = System.IO.File.AppendText("d:\\timelog.txt"))
      31:             {
      32:                 sw.WriteLine("插件【{0}】正在运行。\n", _serviceEntity.Name);
      33:             }
      34:             while (_isRuning)
      35:             {
      36:                 using (var sw =System.IO.File.AppendText("d:\\timelog.txt"))
      37:                 {
      38:                     sw.WriteLine("当前时间:{0:yyyy-MM-dd HH:mm:ss}\n",DateTime.Now);
      39:                 }
      40:                 System.Threading.Thread.Sleep(10000);
      41:             }
      42:         }
      43:  
      44:         public void Stop()
      45:         {
      46:             _isRuning = false;
      47:         }
      48:     }
      49: }

    7、打包插件

    image

    8、安装插件

    image

    image

    image

    安装成功

    image

    9、运行结果

    image

    10.示例打包

    Download

  • 相关阅读:
    软件RAID 0
    逻辑卷管理lvm
    磁盘配额quota
    合并 CentOS 6.8 的两个ISO镜像
    挂载mount
    非交互式添加分区
    磁盘分区-gdisk用法
    C博客作业01--分支、顺序结构
    C语言--第0次作业
    浅议正则表达式
  • 原文地址:https://www.cnblogs.com/LifelongLearning/p/2203790.html
Copyright © 2011-2022 走看看