C# 多线程的使用。如何使用多线程?

2024-11-15 17:01:44
推荐回答(2个)
回答1:

你用线程池(ThreadPool)可以实现,也可以用线程(Thread)实现

for (int i = 0; i < int.Parse(times); i++) //number of threads
{
//Console.WriteLine("thread i = " + i);
//Thread oThread = new Thread(new ParameterizedThreadStart(Beta));
bool FIL = fi == "1" ? true :false;
para p = new para { Finished = (i == int.Parse(times) - 1), Xml = doc.InnerXml, URL = url, num_msgs_processed = i, num_msgs_sent = i, FI = FIL };
// Start the thread
//oThread.Start(p);
//oThread.Join();

ThreadPool.QueueUserWorkItem(Beta, p);
}

回答2:

可以使用Thread 类,详细使用实例和类相关属性方法参见msdn 文档。
http://msdn.microsoft.com/zh-cn/library/system.threading.thread(VS.80).aspx