日期:2014-05-17 浏览次数:20812 次
internal delegate void ThreadOverDelegate(string threadClassID);
/// <summary>
/// 线程执行类
/// </summary>
internal class ThreadClass<T> where T:IMsg
{
//识别ID
string threadClassID = string.Empty;
//处理消息事件
private event MessageQueue<T>.MsgDealDelegate MsgDealEvent;
private event ThreadOverDelegate ThreadOverEvent;
//超时计数器
private readonly System.Timers.Timer timer = new System.Timers.Timer();
//线程同步
private readonly AutoResetEvent thread_startEvent = new AutoResetEvent(false);
//线程锁
private readonly object thread_msgLock = new object();
//超时标记
public bool isTimeout = false;
//执行任务线程
Thread thread;
//消息数据
T Msg;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="_MsgDealEvent">处理消息事件</param>
internal ThreadClass(string _threadClassID, MessageQueue<T>.MsgDealDelegate _MsgDealEvent, ThreadOverDelegate _ThreadOverEvent)
{
threadClassID = _threadClassID;
MsgDealEvent = _MsgDealEvent;
ThreadOverEvent = _ThreadOverEvent;
}
/// <summary>
/// 加入任务
/// </summary>
/// <param name="msg"></param>
internal void AddTask(T msg)
&