I am new and I have a multi-threaded implementation in c #. But the result returns an error.
File <number.txt>
have number 0 to 1000. But the return value is 1 to 1000. Not 0. Please help me understand the problem. Thank you.
static void Number(int number)
{
List<string> l_number = new List<string>(File.ReadAllLines("number.txt"));
Console.WriteLine(l_number[number]);
}
static void Main(string[] args)
{
List<Thread> l_thread = new List<Thread>();
int soThread = 10;
Thread thread1 = new Thread(delegate ()
{
var numnum = 0;
while (true)
{
for (int i = 0; i < soThread; i++)
{
Thread threadnew = new Thread(delegate ()
{
//Console.WriteLine(numnum);
Number(numnum);
});
threadnew.Start();
l_thread.Add(threadnew);
numnum++;
Thread.Sleep(100);
}
foreach (Thread item in l_thread)
{
item.Join();
}
}
});