码迷,mamicode.com
首页 > 其他好文 > 详细

nop 中创建任务(Task)

时间:2020-05-18 14:40:34      阅读:65      评论:0      收藏:0      [点我收藏+]

标签:nload   nop   dom   oid   schedule   config   color   store   service   

NopCommerce 中Task 原理是服务端开启线程定时跑。

1.在数据表ScheduleTask中添加一条数据,

技术图片

 

 2.自定义类,继承ITask 即可

using Data.Log4Net;
using Data.Services.Tasks;
using System;
using System.Net;
using System.Security.Policy;
using System.Web;

namespace Data.Services.Common
{
    /// <summary>
    /// Represents a task for keeping the site alive
    /// </summary>
    public partial class KeepAliveTask : ITask
    {
        //private readonly IStoreContext _storeContext;

        //public KeepAliveTask(IStoreContext storeContext)
        //{
        //    this._storeContext = storeContext;
        //}

        /// <summary>
        /// Executes a task
        /// </summary>
        public void Execute()
        {
            //WriteLog.Info("KeepAliveTask,Execute");
            string domainUrl = System.Configuration.ConfigurationManager.AppSettings["domainUrl"];
            string url = domainUrl + "/keepalive/index";//"http://localhost:8060/keepalive/index";
            WriteLog.Info("KeepAliveTask,url=" + url);
            using (var wc = new WebClient())
            {
                var down = wc.DownloadString(url);
                WriteLog.Info("KeepAliveTask,down=" + down);
            }
        }
    }
}

OK,服务端会每隔60秒 跑 Execute()方法。

nop 中创建任务(Task)

标签:nload   nop   dom   oid   schedule   config   color   store   service   

原文地址:https://www.cnblogs.com/hpbkin/p/12910019.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!