亚洲必赢手机入口自定义配置文件

by admin on 2019年4月5日

第二添加二个.json 文件,比如 setting.json
文件内容如下,记得把公文设置为“复制到输出目录”

先是添加1个.json 文件,比如 setting.json
文件内容如下,记得把文件设置为“复制到输出目录”

{
“ConfigSetting”: {
“XXXName”: “Name”,
“XXXValue”: “Value”
}
亚洲必赢手机入口,}

{
“ConfigSetting”: {
“XXXName”: “Name”,
“XXXValue”: “Value”
}
}

 

 

下来定义3个经受Model 

下来定义四个收受Model 

public class SettingModel
{
public string XXXName { get; set; }

public class SettingModel
{
public string XXXName { get; set; }

public string XXXValue { get; set; }
}

public string XXXValue { get; set; }
}

在 Startup.cs 的主意中 public void ConfigureServices(IServiceCollection
services) 添加上边包车型地铁挂号事件

在 Startup.cs 的措施中 public void ConfigureServices(IServiceCollection
services) 添加下边包车型客车登记事件

 services.Configure<SettingModel>(Configuration.GetSection(“ConfigSetting”));

 services.Configure<SettingModel>(Configuration.GetSection(“ConfigSetting”));

 

 

下一场在任务Controller 只怕是劳动中就能平常使用,使用办法见下边藏青部分:

接下来在职责Controller 恐怕是劳务中就能不荒谬使用,使用方法见下边锌钡白部分:

public class SyncService : IBaseService
{

public class SyncService : IBaseService
{

private readonly System.Timers.Timer _timer;
private readonly ILogger logger;
private readonly SettingModel settingModel;
public SyncService(IOptions<SettingModel>
settingOptons, ILoggerFactory loggerFactory)
{
this.settingModel = settingOptons.Value;
_timer = new System.Timers.Timer(10000);
_timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

private readonly System.Timers.Timer _timer;
private readonly ILogger logger;
private readonly SettingModel settingModel;
public SyncService(IOptions<SettingModel>
settingOptons, ILoggerFactory loggerFactory)
{
this.settingModel = settingOptons.Value;
_timer = new System.Timers.Timer(10000);
_timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

_timer.Interval = 2000;

_timer.Interval = 2000;

_timer.AutoReset = true;
_timer.Enabled = false;
logger = loggerFactory.CreateLogger<SyncService>();
}

_timer.AutoReset = true;
_timer.Enabled = false;
logger = loggerFactory.CreateLogger<SyncService>();
}

private void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine(string.Format(“SyncService:{0:yyyy-MM-dd HH:mm:sss}”,
DateTime.Now));
_timer.Enabled = false;

private void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine(string.Format(“SyncService:{0:yyyy-MM-dd HH:mm:sss}”,
DateTime.Now));
_timer.Enabled = false;

try
{
//do some job;
}
catch (Exception ex)
{
logger.LogError(“SyncService Error {0}:”, ex.Message);
}
Console.WriteLine(string.Format(“SyncService:{0:yyyy-MM-dd HH:mm:sss}”,
DateTime.Now));

try
{
//do some job;
}
catch (Exception ex)
{
logger.LogError(“SyncService Error {0}:”, ex.Message);
}
Console.WriteLine(string.Format(“SyncService:{0:yyyy-MM-dd HH:mm:sss}”,
DateTime.Now));

Thread.Sleep(5 * 60 * 1000);

Thread.Sleep(5 * 60 * 1000);

_timer.Enabled = true;

_timer.Enabled = true;

}

}

public void Start()
{
_timer.Start();
_timer.Enabled = true;
}
public void Stop()
{
_timer.Stop();
_timer.Enabled = false;
}
}

public void Start()
{
_timer.Start();
_timer.Enabled = true;
}
public void Stop()
{
_timer.Stop();
_timer.Enabled = false;
}
}

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图