ke_junjie
2025-06-04 84620534eb627e95811b971a4b552b6a177829bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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);//休眠一天
                //*/
            }
        }
    }
}