110,499
社区成员
发帖
与我相关
我的任务
分享
namespace CompletionCondition
{
public class SharedState
{
public int state;
public SharedState(int state)
{
this.state = state;
}
}
public class Program
{
public static void Main()
{
SharedState state = new SharedState(0);
Thread[] thread = new Thread[5];
for (int i = 0; i < 5; i++)
{
thread[i] = new Thread(new ParameterizedThreadStart(ThreadMain));
thread[i].Start(state);
}
for (int i = 0; i < 5; i++)
{
thread[i].Join();
}
Console.WriteLine("Summarized {0}", state.state);
Console.Read();
}
public static void ThreadMain(object o)
{
SharedState state = o as SharedState;
for (int i = 0; i < 10000; i++)
{
state.state++;
}
}
}
}