首页 > Web开发 > 详细

.NET轻量级任务任务管理类

时间:2017-01-04 22:59:41      阅读:218      评论:0      收藏:0      [点我收藏+]

概述

  最近做项目总是遇到服务跑批等需求,一直想写个任务管理的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

 

.NET轻量级任务任务管理类

原文:http://www.cnblogs.com/xibei666/p/6250435.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!