日期:2014-05-16 浏览次数:20900 次
public static class X
{
private static System.Collections.Generic.Queue<object> queue;
private static int queueLock;
private static void run()
{
do
{
while (System.Threading.Interlocked.CompareExchange(ref queueLock, 1, 0) != 0) System.Threading.Thread.Sleep(0);
object value = queue.Count != 0 ? queue.Dequeue() : null;
queueLock = 0;
if (value == null) break;
try
{
//数据你的处理
}
catch { }
}
while (true);
}
private static void start()
{
queue = new System.Collections.Generic.Queue<object>();
queue.Enqueue(new object());//添加你的数据
for (int threadCount = 10; threadCount != 0; --threadCount) new Thread(run).Start();
}
}