-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
43 lines (38 loc) · 1.32 KB
/
Program.cs
File metadata and controls
43 lines (38 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Threading;
using System.Collections.Generic;
namespace SimpleThread
{
class Program
{
static Queue<int> queue = new Queue<int>();
static Thread mainThread;
static void Main(string[] args)
{
mainThread = Thread.CurrentThread;
ThreadStart childRef = new ThreadStart(ChildThread);
Thread childThread = new Thread(childRef);
childThread.Start();
for (int i = 0; i < 200000; i++)
{
if (i % 10000 == 0)
{
queue.Enqueue(i);
Console.WriteLine("At " + i + " and child thread is " + childThread.ThreadState.ToString());
Thread.Sleep(1000);
}
}
Console.WriteLine("Main Done");
}
static void ChildThread()
{
Thread.Sleep(2000);
while (queue.Count > 0 || !mainThread.ThreadState.ToString().Contains("Stopped"))
{
Console.WriteLine("\t\t\t\tChild thread At " + queue.Dequeue() + " main thread status is " + mainThread.ThreadState.ToString());
Thread.Sleep(2000);
}
Console.WriteLine("child thread done");
}
}
}