zoukankan      html  css  js  c++  java
  • ASP.NET quartz 定时任务

    1.下载

    2.使用例子 Demo

    概述:Quartz 是开源的定时任务工具类,默认每隔10秒执行一次任务,相当于C#的Timer,不断的循环执行(Start 方法),也可以随时停止(ShutDown方法)。 

    一 下载

    下载地址:quartz

    二 使用例子 Demo

    1)引入程序集,必须引入三个,不然报错

    2)IScheduler 和 IJob

    public class Myjob : IJob
        {
            public const string DelayTime = "delay time";
    
            public void Execute(IJobExecutionContext context)
            {
                string key = "quartzKeyCache";
                if (System.Web.HttpRuntime.Cache[key] != null)
                {
                    var temp = (int)System.Web.HttpRuntime.Cache[key];
                    System.Web.HttpRuntime.Cache[key] = temp + 1;
                }
                else
                {
                    System.Web.HttpRuntime.Cache[key] = 1;
                }
            }
        }
    public class QuartzUlity
        {
            public static IScheduler sched;
            public static void Open()
            {
                ISchedulerFactory schedf = new StdSchedulerFactory();
                sched = schedf.GetScheduler();
    
                IJobDetail job = JobBuilder.Create<Myjob>().Build();
                ITrigger trigger = (ITrigger)TriggerBuilder.Create().WithCronSchedule("/10 * * * * ?").Build();
    
                sched.ScheduleJob(job, trigger);
                sched.Start();
            }
    
            public static void Close()
            {
                sched.Shutdown(true);
            }
        }

    3)每隔10秒,修改一次缓存的值,可以打断点随时查看缓存里的实时值。

    天生我材必有用,千金散尽还复来
  • 相关阅读:
    volley框架使用
    Insert Interval
    candy(贪心)
    Best Time to Buy and Sell Stock
    Best Time to Buy and Sell Stock III
    distinct subsequences
    edit distance(编辑距离,两个字符串之间相似性的问题)
    trapping rain water
    word break II(单词切分)
    sudoku solver(数独)
  • 原文地址:https://www.cnblogs.com/ligenyun/p/7729989.html
Copyright © 2011-2022 走看看