【发布时间】:2015-01-07 19:08:57
【问题描述】:
这是我执行线程示例的应用程序,但输出与预期不符,请任何人对此有任何线索
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace OTS_Performence_Test_tool
{
class Program
{
static void testThread(string xx)
{
int count = 0;
while (count < 5)
{
Console.WriteLine(xx );
count++;
}
}
static void Main(string[] args)
{
Console.WriteLine("Hello to the this test app ---");
for (int i = 1; i<=3; i++)
{
Thread thread = new Thread(() => testThread("" + i + "__"));
thread.Start();
}
Console.ReadKey();
}
}
}
但出来却是
3__
3__
3__
3__
3__
3__
3__
3__
3__
3__
4__
4__
4__
4__
4__
究竟发生了什么,任何人都可以解释一下 谢谢
【问题讨论】:
-
预期的输出是什么,为什么会这样?
-
预期为1__五次,2__五次,3__次五次,顺序不重要
标签: c# multithreading