wzp
2021-07-28 864986e4cad03f6b9bba9a7e65379db496b62a6a
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
namespace AsiaINFO.SMS.APPCMPP2.MyThread.DataThread
{
    using AsiaINFO.SMS.APPCMPP2;
    using AsiaINFO.SMS.APPCMPP2.MyThread;
    using AsiaINFO.SMS.BusinessFactory;
    using AsiaINFO.SMS.CMPP2;
    using AsiaINFO.SMS.Entity;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Threading;
 
    public class ReportThread : ThreadBase
    {
        private SyncEvents _reportEvents;
        private Queue<ReportInfo> _reportQueue;
 
        public ReportThread(SyncEvents syncEvents, Queue<ReportInfo> reportQueue) : base(syncEvents)
        {
            if (reportQueue == null)
            {
                throw new Exception("ReportThread参数不能为空!");
            }
            this._reportQueue = reportQueue;
        }
 
        private void DealData(ReportInfo report)
        {
            try
            {
                if (!MTBusiness.UpdateMTInfo(report))
                {
                    if (report.UpdateRetry < 10)
                    {
                        report.UpdateRetry++;
                        this._reportData = report;
                        Thread.Sleep(500);
                    }
                    else
                    {
                        MTBusiness.AddReportWait(report, ShareData.CurrentISMG);
                        string msg = string.Format("更新Report数据超过最大操作次数,记录Report数据 MsgID={0}", report.MSGID);
                        base.OnMsg(msg, MsgLevel.Debug);
                    }
                }
            }
            catch (Exception exception)
            {
                string str2 = string.Format("记录Report数据错误:{0}", exception.Message);
                if (report.DBRetry < 11)
                {
                    report.DBRetry++;
                    this._reportData = report;
                    Thread.Sleep(0x3e8);
                }
                else
                {
                    str2 = string.Format("记录Report数据错误:{0},超过最大操作次数,放弃数据", exception.Message);
                }
                base.OnMsg(str2, MsgLevel.Err);
            }
        }
 
        protected override void Run()
        {
            ReportInfo report = null;
            while (WaitHandle.WaitAny(base._syncEvents.EventArray) != 1)
            {
                object obj2;
            Label_0004:
                Monitor.Enter(obj2 = base._syncSuspendLogLockObject);
                try
                {
                    report = this._reportData;
                    if (report != null)
                    {
                        this.DealData(report);
                        goto Label_0004;
                    }
                }
                finally
                {
                    Monitor.Exit(obj2);
                }
            }
            base.Stop();
        }
 
        public override void Stop()
        {
            if ((base._thread != null) && (base._thread.ThreadState == ThreadState.Suspended))
            {
                base.Stop();
            }
            base._syncEvents.ExitThreadEvent.Set();
        }
 
        private ReportInfo _reportData
        {
            get
            {
                lock (((ICollection) this._reportQueue).SyncRoot)
                {
                    if (this._reportQueue.Count > 0)
                    {
                        return this._reportQueue.Dequeue();
                    }
                }
                return null;
            }
            set
            {
                lock (((ICollection) this._reportQueue).SyncRoot)
                {
                    this._reportQueue.Enqueue(value);
                }
            }
        }
    }
}