C# – First steps with C# and .NET – part 002 .

Today I will show you more about C# and the subject of this tutorial is threads.
First, you need to start a project into your folder. Let’s see my example:

You can use notepad or any editor to edit the Program.cs:

About the thread issue then you need to know is a very complex subject.
My example will show you how the thread works.
First, you need to start the thread and then deal with the thread.
Two methods are used: Start and Join.
Start begins executing at the first line of the method and does not block the calling thread.
Join is a synchronization method that blocks the calling thread (that is, the thread that calls the method) until the thread whose Join method is called has completed.
I used three threads and these threads just start count first 5 sec, next 8 sec and the last is set to 10 sec.
Let’s see the example:

Each thread will write to the output and then will see the time used.
See the output of dotnet run command:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.