考慮從http://www.albahari.com/threading/採取了以下例子:的HelloWorld多線程C#應用程序
using System;
using System.Threading;
class ThreadTest
{
static void Main()
{
Thread t = new Thread (WriteY); // Kick off a new thread
t.Start(); // running WriteY()
// Simultaneously, do something on the main thread.
for (int i = 0; i < 1000; i++) Console.Write ("x");
}
static void WriteY()
{
for (int i = 0; i < 1000; i++) Console.Write ("y");
}
}
如何修改代碼以使WriteY()接受一個字符串參數,這樣我可以有一個線程通「x」和一通「y」?
爲什麼您的方法需要JOIN方法,而不是使用Lamba方法? – ChadD 2012-01-04 02:44:47
這不是「需要」,我只是希望在退出「Main」之前確保我的線程已經退出。 – 2012-01-04 02:54:30
@RobertAllanHenniganLeahy我對你的回覆感興趣,只是用它來測試它,但我有一個如下問題 - 我怎麼能通過多個參數?說我想通過循環計數,所以它不固定在1000.謝謝 – harag 2012-01-04 14:24:47