建立一線程、並在有資料時、啟動執行、沒有資料時就休息、
用在先進先出、前後資料有順序關係時、
#region >><<
protected Queue<object> ArgsQueue;
private System.Threading.Thread SendThread;
protected System.Threading.ManualResetEvent SendEvent;
protected virtual void initArgsQueue()
{
Members = new List<User>();
ArgsQueue = new Queue<object>();
SendEvent = new System.Threading.ManualResetEvent(false);
SendThread = new System.Threading.Thread(new System.Threading.ThreadStart(SendData));
SendThread.Start();
}
protected virtual void disArgsQueue()
{
if (Members != null)
Members.Clear();
Members = null;
if (ArgsQueue != null)
ArgsQueue.Clear();
ArgsQueue = null;
if (SendEvent != null)
SendEvent.Close();
SendEvent = null;
if (SendThread != null)
{
if (SendThread.IsAlive)
{
try
{
SendThread.Abort();
}
catch (System.Threading.ThreadAbortException) { }
}
}
SendThread = null;
}
public virtual void SendData(Queue args)
{
if (isDispose) return;
if (Members.Count == 0) return;
ArgsQueue.Enqueue(args);
SendEvent.Set();
}
protected virtual void SendData()
{
while (!isDispose)
{
try
{
if (SendEvent == null) return;
SendEvent.WaitOne();
if (ArgsQueue == null) return;
else if (ArgsQueue.Count > 0)
{
object args = ArgsQueue.Dequeue();
}
else
SendEvent.Reset();
}
catch (System.Threading.ThreadAbortException) { }
catch (System.ObjectDisposedException) { }
}
}
#endregion
===================
搞了C#
現在來學學維修筆電