This commit is contained in:
2023-01-04 14:34:34 +09:00
parent 968d5c1603
commit c0548e4a32
3 changed files with 66 additions and 3 deletions

View File

@@ -47,6 +47,7 @@
<Compile Include="BasicFuncAction.cs" />
<Compile Include="BasicLambda.cs" />
<Compile Include="BasicLinq.cs" />
<Compile Include="BasicThread.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

View File

@@ -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++;
}
}
}
}

View File

@@ -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();
}