using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SlnMesnac.Repository.service;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace SlnMesnac.Business.Airport
{
    public class AirPortBusiness : BackgroundService
    {
        private readonly IAirportTaskService _airportTaskService;

        public AirPortBusiness(IAirportTaskService airportTaskService)
        {
            _airportTaskService = airportTaskService;
        }

        protected async override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _airportTaskService.CreateDataBase();
            while (!stoppingToken.IsCancellationRequested)
            {
                //执行任务
                Console.WriteLine($"{DateTime.Now}");

                //周期性任务，于上次任务执行完成后，等待5秒，执行下一次任务
                await Task.Delay(500);
            }
            return;
        }
    }
}
