using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ThreadDemo
{
class Program
{
static public List<int> temp = new List<int >();
static public List<Thread> worker = new List<Thread>();
static public List<List<int>> Temporary = new List<List<int>>();
static void Main(string[] args)
{
temp.add(20);
temp.add(10);
temp.add(5);
foreach (int k in temp)
{
int z = 0;
worker[z] = new Thread(() => { sample(k); });
worker[z].Name = "Worker" + z.ToString();
worker[z].Start();
z++;
}
}
public static void sample(int n)
{
List<int> local = new List<int>();
for (int i = 0; i < n; i++)
{
local.Add(i);
}
Temporary.Add(local);
}
}
}
在這個程序時,啓動主程序foreach循環我有螺紋的問題
創建三級螺紋,也將啓動thread.In是第一個線程操作比其他不再那麼這將需要一些時間但其他線程在第一個 之前完成,因爲這個命令在臨時發生了變化。我需要臨時列表順序和臨時列表順序一樣。使用線程可以實現這個功能。線程同步
只是關於語法的一些提示:在C#中,方法名通常以大寫字母開頭,變量/字段名以小寫字母開頭。 – Kiril 2010-06-22 05:45:31
我知道lirik我只是輸入這個程序,例如無論如何謝謝你的評論 – ratty 2010-06-22 05:46:54
沒問題...不要忘記,你可以編輯你的問題後,你已經提交它。如果你想修復語法,你可以編輯你的文章並修復它。 – Kiril 2010-06-22 05:48:55