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 MOInfoThread : ThreadBase
|
{
|
private SyncEvents _moinfoEvents;
|
private Queue<MOInfo> _moinfoQueue;
|
|
public MOInfoThread(SyncEvents syncEvents, Queue<MOInfo> moinfoQueue) : base(syncEvents)
|
{
|
if (moinfoQueue == null)
|
{
|
throw new Exception("MOInfoThread参数不能为空!");
|
}
|
this._moinfoQueue = moinfoQueue;
|
}
|
|
private void DealData(MOInfo moinfo)
|
{
|
try
|
{
|
MOBusiness.AddMOInfo(moinfo);
|
}
|
catch (Exception exception)
|
{
|
string msg = string.Format("记录MO数据错误:{0}", exception.Message);
|
if (moinfo.DBRetry < 11)
|
{
|
moinfo.DBRetry++;
|
this._moinfoData = moinfo;
|
Thread.Sleep(0x3e8);
|
}
|
else
|
{
|
msg = string.Format("记录MO数据错误:{0}, 操过最大操作次数,放弃数据", exception.Message);
|
}
|
base.OnMsg(msg, MsgLevel.Err);
|
}
|
}
|
|
protected override void Run()
|
{
|
MOInfo moinfo = null;
|
while (WaitHandle.WaitAny(base._syncEvents.EventArray) != 1)
|
{
|
object obj2;
|
Label_0004:
|
Monitor.Enter(obj2 = base._syncSuspendLogLockObject);
|
try
|
{
|
moinfo = this._moinfoData;
|
if (moinfo != null)
|
{
|
this.DealData(moinfo);
|
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 MOInfo _moinfoData
|
{
|
get
|
{
|
lock (((ICollection) this._moinfoQueue).SyncRoot)
|
{
|
if (this._moinfoQueue.Count > 0)
|
{
|
return this._moinfoQueue.Dequeue();
|
}
|
}
|
return null;
|
}
|
set
|
{
|
lock (((ICollection) this._moinfoQueue).SyncRoot)
|
{
|
this._moinfoQueue.Enqueue(value);
|
}
|
}
|
}
|
}
|
}
|