首页 > 其他 > 详细

nop 中创建任务(Task)

时间:2020-05-18 14:50:47      阅读:63      评论:0      收藏:0      [点我收藏+]

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)

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

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