-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public class Program | ||
{ | ||
static void Main() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
public class Program | ||
{ | ||
static void Main() | ||
{ | ||
// Task runs on background thread | ||
Task task1 = new Task(Print); | ||
task1.Start(); | ||
task1.Wait(); | ||
|
||
Task.Run(() => | ||
{ | ||
Console.WriteLine("Halo dunia"); | ||
}); | ||
|
||
Task task2 = Task.Run(() => | ||
{ | ||
Console.WriteLine("Do something"); | ||
}); | ||
|
||
Task task3 = Task.Run(() => | ||
{ | ||
Console.WriteLine("Do another thing"); | ||
}); | ||
|
||
Task.WaitAll(task2, task3); | ||
|
||
Console.WriteLine("Task delay started"); | ||
Task task4 = Task.Run(async () => | ||
{ | ||
Console.WriteLine("Process A"); | ||
await Task.Delay(1000); | ||
Console.WriteLine("Process finished"); | ||
}); | ||
task4.Wait(); | ||
Console.WriteLine("Task delay finished"); | ||
|
||
} | ||
|
||
static void Print() { | ||
Console.WriteLine("Hello world"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
| ||
using System.Diagnostics; | ||
|
||
public class Program | ||
{ | ||
static void Main() | ||
{ | ||
Thread t1 = new Thread(ProcessA); | ||
Thread t2 = new Thread(ProcessB); | ||
|
||
// it's uncertain which thread is started first | ||
t1.Start(); | ||
t2.Start(); | ||
Console.WriteLine("Finished"); | ||
|
||
// Blocking main thread | ||
Stopwatch sw = new(); | ||
sw.Start(); | ||
Thread.Sleep(1000); // 1000 miliseconds | ||
sw.Stop(); | ||
Console.WriteLine("Main thread has been blocked in " + sw.Elapsed); | ||
|
||
// Lambda expression | ||
Thread t3 = new Thread(() => | ||
{ | ||
Console.WriteLine("My thread 3"); | ||
}); | ||
Thread t4 = new Thread(() => | ||
{ | ||
Console.WriteLine("My thread 4"); | ||
}); | ||
|
||
t3.Start(); | ||
t4.Start(); | ||
|
||
Thread t5 = new Thread(PrintX); | ||
Thread t6 = new Thread(PrintY); | ||
|
||
t5.Start(); | ||
t6.Start(); | ||
} | ||
|
||
static void ProcessA() | ||
{ | ||
Console.WriteLine("Hello world"); | ||
} | ||
|
||
static void ProcessB() | ||
{ | ||
Console.WriteLine("Halo dunia"); | ||
} | ||
|
||
static void PrintX() | ||
{ | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
Console.Write("x"); | ||
} | ||
} | ||
|
||
static void PrintY() | ||
{ | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
Console.Write("y"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |