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