当前位置: 首页 > news >正文

俄罗斯网站设计如何组建一个小型局域网

俄罗斯网站设计,如何组建一个小型局域网,陕西省建设网站 五大员过期,南充市房地产备案查询项目中需要用到QuartZ执行定时任务#xff0c;在此记录一下学习过程。 Quartz安装 在VS2022中#xff0c;通过Nuget包管理器安装Quartz 3.8.1 #xff0c;这是.net 6 依赖的最高版本。 创建定时器任务 1、创建QuartzConfigurator 新建QuartzConfiguratorExtensions类在此记录一下学习过程。 Quartz安装 在VS2022中通过Nuget包管理器安装Quartz 3.8.1 这是.net 6 依赖的最高版本。 创建定时器任务 1、创建QuartzConfigurator 新建QuartzConfiguratorExtensions类用于注册触发器和任务代码如下 /// summary/// 添加任务和触发器/// /summary/// typeparam nameT/typeparam/// param namequartz/param/// param nameconfig/param/// exception crefException/exceptionpublic static void AddJobAndTriggerT(this IServiceCollectionQuartzConfigurator quartz, IConfiguration config) where T : IJob{// Use the name of the IJob as the appsettings.json keystring jobName typeof(T).Name;// Try and load the schedule from configurationvar configKey $Quartz:{jobName};var cronSchedule config[configKey];// Some minor validationif (string.IsNullOrEmpty(cronSchedule)){throw new Exception($No Quartz.NET Cron schedule found for job in configuration at {configKey});}// register the job as beforevar jobKey new JobKey(jobName);quartz.AddJobT(opts opts.WithIdentity(jobKey));quartz.AddTrigger(opts opts.ForJob(jobKey).WithIdentity(jobName -trigger).WithCronSchedule(cronSchedule)); // use the schedule from configuration}/// summary/// 添加任务和触发器带参数传递/// /summary/// typeparam nameT/typeparam/// param namequartz/param/// param nameconfig/param/// param namekeyValuePairs需要传递的参数/param/// param nameIsTriggerJobDataMap默认通过 工作描述时传递参数/param/// exception crefException/exceptionpublic static void AddJobAndTriggerWithParameterT(this IServiceCollectionQuartzConfigurator quartz, IConfiguration config,IDictionarystring, object? keyValuePairs null, bool isJobDetailJobDataMap true) where T : IJob{// Use the name of the IJob as the appsettings.json keystring jobName typeof(T).Name;// Try and load the schedule from configurationvar configKey $Quartz:{jobName};var cronSchedule config[configKey];// Some minor validationif (string.IsNullOrEmpty(cronSchedule)){throw new Exception($No Quartz.NET Cron schedule found for job in configuration at {configKey});}// register the job as beforevar jobKey new JobKey(jobName);if (keyValuePairs ! null isJobDetailJobDataMap){switch (isJobDetailJobDataMap){case true:quartz.AddJobT(opts opts.WithIdentity(jobKey).UsingJobData(new JobDataMap(keyValuePairs)));quartz.AddTrigger(opts opts.ForJob(jobKey).WithIdentity(jobName -trigger).WithCronSchedule(cronSchedule)); // use the schedule from configurationbreak;case false:quartz.AddJobT(opts opts.WithIdentity(jobKey));quartz.AddTrigger(opts opts.ForJob(jobKey).WithIdentity(jobName -trigger).WithCronSchedule(cronSchedule).UsingJobData(new JobDataMap(keyValuePairs))); // use the schedule from configurationbreak;}}else{quartz.AddJobT(opts opts.WithIdentity(jobKey));quartz.AddTrigger(opts opts.ForJob(jobKey).WithIdentity(jobName -trigger).WithCronSchedule(cronSchedule)); // use the schedule from configuration}} 2、在Program.cs 中注入服务 builder.Services.AddQuartz(q {创建计划单元时间轴载体//StdSchedulerFactory schedulerFactory new StdSchedulerFactory();//var scheduler await schedulerFactory.GetScheduler();//await scheduler.Start();q.UseMicrosoftDependencyInjectionJobFactory();// Register the job, loading the schedule from configurationq.AddJobAndTriggerFromKingdeeWorkerJob(builder.Configuration); }); builder.Services.AddQuartzHostedService(q q.WaitForJobsToComplete true); 3、创建工作单元WorkerJob 新建类TestWorkerJob并继承IJob代码如下 [PersistJobDataAfterExecution]//在执行完成后保留JobDataMap数据[DisallowConcurrentExecution]//不允许并发执行即必须等待上次完成后才能执行下一次public class TestWorkerJob : IJob{private readonly ILoggerTesteWorkerJob _logger;public TestWorkerJob(ILoggerTestWorkerJob logger){ _logger logger;}public Task Execute(IJobExecutionContext context){_logger.LogInformation(DateTime.Now --- Hello world!);Task.Delay(50000);Thread.Sleep(10000);return Task.CompletedTask;}} 假如我们的定时任务执行一次需要耗时比较久而且后一次执行需要等待前一次完成并且需要前一次执行的结果作为参考那么就需要设置任务的任性。因为默认情况下工作单元在每一次运行都是一个新的实例相互之间独立运行互不干扰。所以如果需要存在一定的关联就要设置任务的特性主要有两个如下所示 [PersistJobDataAfterExecution]//在执行完成后保留JobDataMap数据 [DisallowConcurrentExecution]//不允许并发执行即必须等待上次完成后才能执行下一次 以上两个特性只需要标记在任务对应的类上即可。 4、appsettings.json配置 在appsettings.json文件中添加一项Quartz子项的必须与WorkerJob的名字保持一致value是Cron表达式 {Quartz: {FromKingdeeWorkerJob: 0/5 * * * * ?} } 然后启动项目就可以看到任务可以正常运行啦。 最后 最后附上学习链接 .NET6Quartz实现定时任务_.net6 quartz-CSDN博客 KSO - 在.NET6中项目级使用配置Quartz.NET定时任务并使用IHostedService实现项目启动自动加载任务常用的Corn表达式_net6 webapi 在配置中引入注入quartz-CSDN博客
http://www.pierceye.com/news/999477/

相关文章:

  • 网站做推广需要什么条件开一家网络公司需要什么条件
  • 能制作网站的软件wordpress转移至typecho
  • 荆州网站建设流程英文网站建设推广
  • 网站后台素材建e室内设计网官网全景效果图
  • 国外 网站页面设计中国知名的建网站的公司
  • pc网站做移动端适配宁波高质量品牌网站设计厂家
  • 淘宝客网站需要备案建筑材料网站建设
  • c 是用来做网站的吗网易蜂巢 wordpress
  • 网站主题模板制作百润网站建设
  • 搜狗网站排名软件国家城乡建设部网站
  • 专业网站推广服务咨询网站怎么可以被收录
  • 怎么自己做网站挂到百度上通号建设集团有限公司
  • 建设图片展示网站林萌荣温州市网页制作
  • 企业门户网站内容建设如何一个空间做多个网站
  • 行业网站源码网站建设福永附近网络公司
  • 建设网站哪个便宜ps做网站的优点
  • 网站制作中的更多怎么做盘锦市建设银行网站
  • 广西响应式网站建设男女做暧网站
  • 网站建设中心开发公司对施工单位管理措施
  • 青岛网站建设方案优化宋祖儿在哪个网站做网红
  • 莆田网站制作价格wordpress占用带宽
  • 网站用图片做背景搜索引擎推广一般包括哪些
  • 网站首页设计html代码可以发广告的平台
  • 做网站的技术哪个简单泰安吧贴吧
  • 网站制作厂家政务网站开发方案
  • 爱站工具卡片式网站
  • 计算机网站开发图片湛江城乡建设局网站
  • 广州个性化网站开发代做网站关键词
  • 如何开发一个手机网站北京推广网站
  • 企业网站建设合作合同wordpress国产定制主题