diff --git a/BasicGramms/BasicGramms/BasicGramms.csproj b/BasicGramms/BasicGramms/BasicGramms.csproj index 50bf8ad..8c81f5c 100644 --- a/BasicGramms/BasicGramms/BasicGramms.csproj +++ b/BasicGramms/BasicGramms/BasicGramms.csproj @@ -47,6 +47,7 @@ + diff --git a/BasicGramms/BasicGramms/BasicThread.cs b/BasicGramms/BasicGramms/BasicThread.cs new file mode 100644 index 0000000..6ff2cf4 --- /dev/null +++ b/BasicGramms/BasicGramms/BasicThread.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace BasicGramms +{ + internal class BasicThread + { + private Thread globalThread; + public void DoTest() + { + Thread t1 = new Thread(DoThreadJob1); + Thread t2 = new Thread(DoThreadJob2); + globalThread = new Thread(DoGlobaThreadJob); + + globalThread.Start(); + + t1.Start(); + t2.Start(); + } + + private void DoThreadJob1() + { + while (true) + { + Console.WriteLine("Do thread job 1"); + + Thread.Sleep(1000); + } + } + + private void DoThreadJob2() + { + while (true) + { + Console.WriteLine("Do thread job 2"); + + Thread.Sleep(1000); + } + } + + private void DoGlobaThreadJob() + { + int i = 0; + while (true) + { + if (i >= 10) + globalThread.Abort(); + + Console.WriteLine($"Do global thread job (count: {i})"); + Thread.Sleep(1000); + i++; + } + } + } +} diff --git a/BasicGramms/BasicGramms/Program.cs b/BasicGramms/BasicGramms/Program.cs index f72ea00..88653a8 100644 --- a/BasicGramms/BasicGramms/Program.cs +++ b/BasicGramms/BasicGramms/Program.cs @@ -25,9 +25,12 @@ namespace BasicGramms //BasicLinq linq = new BasicLinq(); //linq.DoTest(); - BasicFuncAction funcAction = new BasicFuncAction(); - funcAction.DoFuncTest(); - funcAction.DoActionTest(); + //BasicFuncAction funcAction = new BasicFuncAction(); + //funcAction.DoFuncTest(); + //funcAction.DoActionTest(); + + BasicThread thread = new BasicThread(); + thread.DoTest(); Console.ReadKey(); }