项目作者: clintnetwork

项目描述 :
.Net Core 3 Manager Background Service
高级语言: C#
项目地址: git://github.com/clintnetwork/circle.git
创建时间: 2020-04-05T03:33:13Z
项目社区:https://github.com/clintnetwork/circle

开源协议:MIT License

下载




Circle



About Circle



.Net Core 3 Manager Background Service.


Introduction

Circle is a .Net Core 3 Manager Background Service, that expose an API to handle it.

You simply need to add AddCircle() in the services collection.

Startup.cs

  1. public void ConfigureServices(IServiceCollection services)
  2. {
  3. services.AddCircle(options =>
  4. {
  5. options.Period = TimeSpan.FromSeconds(5);
  6. options.UseHandler<Work>();
  7. });
  8. }

Create a Job

You need to create a new class that inherits from IWorkHandler, and write the task that need to be executed.

  1. public class Work : IWorkHandler
  2. {
  3. public void DoWork()
  4. {
  5. Console.WriteLine("Test!");
  6. }
  7. }

Control the Job

You can use CircleControl class to start, stop or restart the service.

  1. public class HomeController : Controller
  2. {
  3. private readonly CircleControl _circle;
  4. public HomeController(CircleControl circle)
  5. {
  6. _circle = circle;
  7. }
  8. public IActionResult Stop()
  9. {
  10. _circle.Stop();
  11. return Ok();
  12. }
  13. }