.NET轻量级任务管理类

概述

  最近做项目总是遇到服务跑批等需求,一直想写个任务管理的DLL,现在整理了一下思路,编写了一个DLL类库,使用方便。只要调用的子类继承服务基类便可以实现任务的整体调度。先看看页面效果;

使用方式

1、任务的子类服务基础类BaseService,重新父类的执行任务的方法ExecAction和配置服务的方法IntialConfig;

   public class MyTask : BaseService
    {
        public override void ExecAction()
        {
            this.TrackRunLog("生成报表", "开始生成报表服务");
        }

        public override void IntialConfig()
        {
            this.ServiceTitle = "生成报表服务";
        }
    }

2、通过类库下的ServiceRepertory来查询当前服务实例以及启动服务:

  a>、ServiceRepertory.StartService(实例)启动服务;

  b>、ServiceRepertory.StopService(实例)停止服务;

  c>、ServiceRepertory.ServiceList()获取当前所有服务实例;

  d>、ServiceRepertory.StartAllService()启动当前编写的所有服务实例;

     事例代码如下:

        public ActionResult About()
        {
            ServiceRepertory.StartAllService();
            List<BaseService> TaksResult = ServiceRepertory.ServiceList();
            return View(TaksResult);
        }

public ActionResult Service(string serId,string opeart) { BaseService TaskService= ServiceRepertory.ServiceList().SingleOrDefault(p=>p.ServiceID.ToString()==serId); if (TaskService != null) { if (opeart.ToLower().Equals("start")) { ServiceRepertory.StartService(TaskService); } else { ServiceRepertory.StopService(TaskService); } } return Content("操作成功"); }

 3、下载地址

DEMO下载地址: http://pan.baidu.com/s/1nvEvtmp

DLL下载地址:http://pan.baidu.com/s/1slxYfHr

原文地址:https://www.cnblogs.com/xibei666/p/6250435.html