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