The use of Quartz in C#

The use of Quartz in C# Install the NuGet package: Open the project in Visual Studio, right click on the project name, select “Manage NuGet Packages”, search for “Quartz” and install. Create a job: Create a class that implements the IJob interface that contains an Execute method that will be called when the job runs. For example: public class MyJob : IJob { public Task Execute( IJobExecutionContext context) { Console.WriteLine(“Hello, world!”); return Task.CompletedTask ; } } Pass data to Job: // Create a JobDataMap object JobDataMap jobDataMap = new JobDataMap(); // to JobDataMap Add parameters in jobDataMap.Add(“param1”, “Hello”); jobDataMap.Add(“param2”, “World”); // Create a JobDetail object, set JobDataMap JobDetail jobDetail = JobBuilder. Create() .UsingJobData(jobDataMap) .Build(); // in Job Get parameters in the class public class MyJob : IJob { public void</span span> Execute(IJobExecutionContext context) { JobDataMap jobDataMap = context.JobDetail.JobDataMap; string param1 = jobDataMap. GetString(“param1”); string param2 = jobDataMap. GetString(“param2”); Console.WriteLine(“{0} {1}”, param1, param2); } } Note: Every time a job is executed, a new job object will be created and the data in the JobDataMap will be passed to it. This means that even if you store some state or data in the job, they will not be preserved the next…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索