using Common.Logging;
|
using System;
|
using System.ServiceProcess;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using System.Collections.Generic;
|
using Newtonsoft.Json;
|
using iWareCommon.Utils;
|
using log4net;
|
using iWareSql.DataAccess;
|
|
namespace iWarePastDueService
|
{
|
/// <summary>
|
/// 过期料服务
|
/// </summary>
|
public partial class iWarePastDueService : ServiceBase
|
{
|
private static readonly string defaultTime = ConfigHelper.GetConfigString("DefaultPastDueTime");
|
static CancellationTokenSource cancelTokenSource = new CancellationTokenSource();
|
private readonly Common.Logging.ILog logger;
|
public iWarePastDueService()
|
{
|
InitializeComponent();
|
logger = Common.Logging.LogManager.GetLogger(GetType());
|
Task.Factory.StartNew(PastDueMaterialThread, cancelTokenSource.Token);
|
}
|
|
protected override void OnStart(string[] args)
|
{
|
|
logger.Info("过期料服务成功启动");
|
}
|
|
protected override void OnStop()
|
{
|
cancelTokenSource.Cancel();
|
logger.Info("过期料服务成功终止");
|
}
|
|
protected override void OnPause()
|
{
|
}
|
|
protected override void OnContinue()
|
{
|
}
|
|
|
private void PastDueMaterialThread()
|
{
|
//判断是否取消任务
|
while (!cancelTokenSource.IsCancellationRequested)
|
{
|
try
|
{
|
logger.Info("一次过期料处理开始");
|
|
|
|
logger.Info("一次过期料处理结束");
|
|
|
}
|
catch (Exception e)
|
{
|
logger.Error("一次过期料处理错误:" + e.Message, e);
|
}
|
|
//Thread.Sleep(5000);//休眠
|
Thread.Sleep(Convert.ToInt32(defaultTime) * 60 * 60 * 1000);//休眠一天
|
//*/
|
}
|
}
|
}
|
}
|