首页 > 其他分享 >QuartzNet在blazor-winform的使用

QuartzNet在blazor-winform的使用

时间:2023-09-10 17:23:09浏览次数:37  
标签:serviceProvider await synchronousService QuartzNet scheduler services blazor pub

通过构造函数获取ISchedulerFactory   
 private async void InitJob()
 {

     var _scheduler = await _schedulerFactory.GetScheduler();
     _scheduler.JobFactory = new QuartzJobFactory(_serviceProvider); ;// await factory.GetScheduler();

     IJobDetail job = JobBuilder.Create<QuartzJobServer>()//
             .WithIdentity("job1", "group1")
             .Build();

     ITrigger trigger = TriggerBuilder.Create()
             .WithIdentity("trigger1", "group1")
             //.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever())
              .WithCronSchedule(coravelConfig.CustomCorn!)
             .Build();

     await _scheduler.ScheduleJob(job, trigger);
     await _scheduler.Start();


 }

  

public class QuartzJobFactory : IJobFactory
{
    private readonly IServiceProvider _serviceProvider;

    public QuartzJobFactory(IServiceProvider serviceProvider)
    {
        _serviceProvider = serviceProvider;
    }

    public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
    {
        return _serviceProvider.GetService<QuartzJobServer>()!;
    }

    public void ReturnJob(IJob job)
    {
        var disposable = job as IDisposable;
        disposable?.Dispose();
    }
    //public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
    //{
    //    throw new NotImplementedException();
    //}

    //public void ReturnJob(IJob job)
    //{
    //    throw new NotImplementedException();
    //}
}

  

public class QuartzJobServer : IJob
{
    private readonly ISynchronousService _synchronousService;
    public QuartzJobServer(
         ISynchronousService synchronousService
        // IServiceScopeFactory serviceScopeFactory
        )
    {
        _synchronousService = synchronousService;// serviceScopeFactory.CreateScope().ServiceProvider.GetService<ISynchronousService>()!;// synchronousService;
    }

    public async Task Execute(IJobExecutionContext context)
    {
        await _synchronousService.GetPayData(DateTime.Now.ToString("yyyyMMdd"), TypeEnum.New);
        
        await Task.CompletedTask;
    }


}

  

   services.AddScoped<MainFrom>();
   services.AddWindowsFormsBlazorWebView();
   services.AddMasaBlazor();
   services.AddScoped<QuartzJobServer>();
   services.AddScoped<ISynchronousService, SynchronousService>();
   services.AddScoped<IWXPayDataService, WXPayDataService>();
   services.AddLogging(x => x.AddNLog());
   services.AddQuartz();
   services.AddSignalR();
   services.AddQuartzHostedService(x => x.WaitForJobsToComplete = true);
   services.AddSingleton<IConfiguration>(configBuild);
   var config = configBuild.GetSection("CustomParameter").Get<CoravelConfig>();
   var dbConfig = configBuild.GetSection("ConnectionStrings").Get<DbConfig>();
   services.Configure<CoravelConfig>(x => x.CustomCorn = config!.CustomCorn);
   services.Configure<DbConfig>(x => x.ConnString = dbConfig!.ConnString);
   return services.BuildServiceProvider();
//这里有些是我自己的,用的blazor-winform,自己看着删除

  

标签:serviceProvider,await,synchronousService,QuartzNet,scheduler,services,blazor,pub
From: https://www.cnblogs.com/liujian1368928/p/17691518.html

相关文章

  • 界面控件DevExpress WinForms工具栏菜单组件,模拟流行办公软件!
    DevExpressWinForms的工具栏和菜单组件灵感来自于MicrosoftOffice,并针对WinForms开发人员进行了优化,可以帮助开发者快速模拟当下流行的办公软件应用程序。DevExpressWinForms有180+组件和UI库,能为WindowsForms平台创建具有影响力的业务解决方案。同时能完美构建流畅、美观且......
  • cefsharp - WinForms 和 Wpf 示例之间的巨大性能差异
    https://www.coder.work/article/7217456我注意到在使用 http://www.vsynctester.com 时CefSharp.WinForms.Example和CefSharp.Wpf.Example之间存在非常重要的性能差异(以FPS计)在我的显卡控制面板和CefExampleInit()中的设置中关闭VSync时settings.CefCommandLi......
  • C#Winform怎么让控件随着主界面大小变化
    usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceWindowsFormsApplication1{publicpar......
  • Winform无边框窗体实现拖动
    winfrom窗体自带的边框不好看,可以将FormBorderStyle设置为None去除边框,但这样窗体无法拖动下面记录无边框窗体拖动的几种方法[参考其他博主的]:1.Form触发MouseDown事件时,记录鼠标坐标:rawPoint=e.Location;MouseMove时根据鼠标坐标的移动偏移量,设置窗体位置同步变化:void......
  • Winform实现验证码功能
    介绍下Winform实现验证码的步骤:首先拖入控件:PictureBox显示验证码;TextBox输入验证码;Check按钮;Label标签-点击更换验证码;1.随机产生一个4位的字符串,由数字,大小写字母组成:stringRandomCode(){stringretCode="";for(inti=0;i<4;i++){while......
  • winform,c#左链接查询两张表或多张表,数据库正常,但是发现查出来的同一条记录变成了好几
    这个样子就是犯了笛卡尔积,我有两张表那我自己项目来说一下吧:a表的内容如下: b表的内容如下: 到这里,你会发现,又五六个字段内容是一模一样的,该字段两张表都用,那么查询出来数据翻倍就很好解决了在where后面加上a.字段1=b.字段1and......anda.字段n=b.字段n就可以了......
  • WPF使用Blazor的快速案例
    下面我们将讲解在WPF中使用Blazor,并且使用Blazor做一些文件编辑操作,下面是需要用到的东西WPFBlazorMasaBlazorMonaco安装MasaBlazor模板使用CMD指令安装模板dotnetnewinstallMASA.Template新建MasaBlazorWPFApp找到如图的模板,然后点击下一步下一步,新建......
  • Blazor下的serilog
    前段时间学习了blazor,按教程一步一步学习的,但是发现borad.razor上的游戏第一个总是对应不上,我觉得是css没有写好的原因,所以没有过多探究。近日学习了serilog,发现配置起来好像比log4net要简单,深入研究了一下,觉得挺有意思。于是想采用日志的方式把前面的问题找出来,所以又学了一系......
  • 如何将现有的`Blazor`项目的主题切换写的更好看?
    如何将现有的Blazor项目的主题切换写的更好看?在现有的系统当中,我们的主题切换会比较生硬,下面我们将基于MasaBlazor实现好看的扩散主题切换的样式效果。安装MASA.TemplatedotnetnewinstallMASA.Template创建MasaBlazor项目打开vs2022选择serverapp模板打开wwwroot......
  • MAUI+Masa Blazor APP 各大商店新手发布指南(二)小米篇
    目录前言审核注意事项准备材料测试与审核总结前言先说一下我们上架厂家应用商店的原因:除了方便用户下载之外,需要厂家的离线推送和微信内容分享等都需要上架应用商店(微信分享不上架有调用次数限制)。如果你的App需要在国内使用离线推送功能,也就是App不启动的场景下接收消息推送,......