I have a list List<int> Test
and in order to do testing I need to make basic threads, one for filling and second for showing items from same randomly. So, the task is to fill and show randomly result in console. Of course, the problem is that my method for showing has that list as a parameter, so instance of the same might be the thing to solve. Here is my code which is just filling and then showing the items:
static void Main(string[] args)
{
List<int> testList = new List<int>();
System.Threading.Thread.Sleep(300);
for (int y = 0; y < 50; y++)
{
testList.Add(y);
Console.WriteLine(string.Format("Added item {0}!", y));
};
Thread testThread1 = new Thread(() => FillList(testList));
testThread1.Start();
Console.ReadKey();
}
public static void FillList(List<int> pTestList)
{
foreach(int x in pTestList)
{
System.Threading.Thread.Sleep(1000);
Console.WriteLine(x.ToString());
}
}
UPDATE:
I want to show in my console a couple of "Added item" and items. So to mix the first part and the second from the image.