Skip to content

Commit

Permalink
Add W5 D3 programs
Browse files Browse the repository at this point in the history
  • Loading branch information
cvpfus committed Oct 4, 2023
1 parent 995a59f commit 0bbe3ce
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 2 deletions.
27 changes: 25 additions & 2 deletions FormulatrixBootcamp.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
Expand Down Expand Up @@ -133,6 +133,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "W5 D1", "W5 D1", "{2A99B32E
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarbageCollection", "W5 D1\GarbageCollection\GarbageCollection.csproj", "{2739F473-20E7-4786-AC1F-2479A2E18A83}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "W5 D3", "W5 D3", "{FC559EAF-E754-4775-A039-64B804F331A8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Threading", "W5 D3\Threading\Threading.csproj", "{7A140AEF-0702-44C9-8F9A-972664EB83C9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Task", "W5 D3\Task\Task.csproj", "{C71461E0-7028-4153-94DC-75B522D07B10}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsyncAwait", "W5 D3\AsyncAwait\AsyncAwait.csproj", "{CCE2C0C8-CD08-44DA-AD87-32848B8B64A7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -347,12 +355,26 @@ Global
{2739F473-20E7-4786-AC1F-2479A2E18A83}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2739F473-20E7-4786-AC1F-2479A2E18A83}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2739F473-20E7-4786-AC1F-2479A2E18A83}.Release|Any CPU.Build.0 = Release|Any CPU
{7A140AEF-0702-44C9-8F9A-972664EB83C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A140AEF-0702-44C9-8F9A-972664EB83C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A140AEF-0702-44C9-8F9A-972664EB83C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A140AEF-0702-44C9-8F9A-972664EB83C9}.Release|Any CPU.Build.0 = Release|Any CPU
{C71461E0-7028-4153-94DC-75B522D07B10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C71461E0-7028-4153-94DC-75B522D07B10}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C71461E0-7028-4153-94DC-75B522D07B10}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C71461E0-7028-4153-94DC-75B522D07B10}.Release|Any CPU.Build.0 = Release|Any CPU
{CCE2C0C8-CD08-44DA-AD87-32848B8B64A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CCE2C0C8-CD08-44DA-AD87-32848B8B64A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CCE2C0C8-CD08-44DA-AD87-32848B8B64A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CCE2C0C8-CD08-44DA-AD87-32848B8B64A7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2739F473-20E7-4786-AC1F-2479A2E18A83} = {2A99B32E-4EA2-467B-A477-CB0844233CDC}
{CCE2C0C8-CD08-44DA-AD87-32848B8B64A7} = {FC559EAF-E754-4775-A039-64B804F331A8}
{C71461E0-7028-4153-94DC-75B522D07B10} = {FC559EAF-E754-4775-A039-64B804F331A8}
{7A140AEF-0702-44C9-8F9A-972664EB83C9} = {FC559EAF-E754-4775-A039-64B804F331A8}
{77D0C1C7-A06B-4E05-9458-873709BD4BFD} = {44C682DF-E1C9-4394-813D-0CB989CD9262}
{AA5CB577-831E-40F5-AABD-AFF7C56F8A57} = {44C682DF-E1C9-4394-813D-0CB989CD9262}
{1A0A5FD8-8FC2-4ECA-8EB0-BAC6DF70E7BF} = {0458C07F-2B31-4DB7-97E4-315800A0B2C0}
Expand Down Expand Up @@ -405,5 +427,6 @@ Global
{78E07498-23C7-4F38-895B-48EA5BCC8104} = {91FC4BEC-1535-4218-88E7-774E73FCFB89}
{2AD188A5-50C3-407C-BAE4-8EED634E2BE5} = {91FC4BEC-1535-4218-88E7-774E73FCFB89}
{B48AD888-F0FA-4879-8F05-BB765527F212} = {91FC4BEC-1535-4218-88E7-774E73FCFB89}
{2739F473-20E7-4786-AC1F-2479A2E18A83} = {2A99B32E-4EA2-467B-A477-CB0844233CDC}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions W5 D3/AsyncAwait/AsyncAwait.csproj
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>
7 changes: 7 additions & 0 deletions W5 D3/AsyncAwait/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class Program
{
static void Main()
{

}
}
42 changes: 42 additions & 0 deletions W5 D3/Task/Program.cs
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");
}
}
10 changes: 10 additions & 0 deletions W5 D3/Task/Task.csproj
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>
68 changes: 68 additions & 0 deletions W5 D3/Threading/Program.cs
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");
}
}
}
10 changes: 10 additions & 0 deletions W5 D3/Threading/Threading.csproj
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>

0 comments on commit 0bbe3ce

Please sign in to comment.