Why List of Task resulting wrong result. Anyone can give direction?
This my code so far.
static string[] kk = new string[] { "a", "b", "c", "d", "e", "f" };
static void Main(string[] args)
{
//Parallel.For(0, 10, i => Test(i));
//Console.ReadLine();
foreach(string str in kk)
{
Task<string> task = Task.Factory.StartNew(() => Test(str));
listTask.Add(task);
}
do
{
Thread.Sleep(100);
}while(!Task.WaitAll(listTask.ToArray(),1000));
foreach (Task<string> task in listTask)
{
Console.WriteLine(task.Status.ToString() + " : " + task.Result);
}
Console.ReadLine();
}
private static string Test(string i)
{
return "test " + i;
}
I expecting result like this:
test a test b test c test d test e test f
But my code above resulting like this: test f test f test f test f test f test f
Thanks in advance.