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);
}
}
}
in this program i have the problem in thread when start the foreach loop in main program creates the three thread and also starts that thread.In that first thread operation is longer than other so it will take some time but other thread completed before the first
due to this order in temporary is changed .i need temporary list order as same as temp list order.how can achieve this using thread
Here is a quick stab at your code:
Now the temporary list should contain the other lists in the correct order (same as your tmp order). Your title does mention scheduling, but I’m not sure why you need scheduling here or what exactly you’re trying to learn about scheduling.