Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize scheduled tasks with FluentScheduler

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces how to use FluentScheduler to achieve scheduled tasks, the content is very detailed, interested friends can use for reference, I hope it can be helpful to you.

1.NuGet downloads FluentScheduler control

two。 Write a class. Inherit the Registry class

/ / /

/ / scheduled tasks

/ / /

Public class FluentScheduler:Registry

{

Public FluentScheduler ()

{

Schedule (() = > Class1.Test1 ()) .ToRunOnceIn (1000). Milliseconds (). Between (16, 25, 16, 28)

Schedule (() = > Class1.Test2 ()). ToRunNow (). AndEvery (2000). Milliseconds ()

Schedule (). ToRunNow (). AndEvery (1). Hours ()

Schedule (() = > {Console.WriteLine ("printed");}) .ToRunNow () .AndEvery (2000) .Milliseconds ()

}

}

3. Write regular execution tasks, according to the method of use, whether to implement IJob interface

Public class Class1

{

Public static void Test1 ()

{

Console.WriteLine ("Class1---Test1 executed")

}

Public static void Test2 ()

{

Console.WriteLine ("Class1---Test2 executed")

}

}

Public class Class2:IJob

{

Public void Execute ()

{

Console.WriteLine ("Class2---Execute executed")

}

}

4. Initialize timer

JobManager.Initialize (new FluentScheduler ())

On how to use FluentScheduler to achieve scheduled tasks to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report