From the course: Threading in C#

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Shared resources demo

Shared resources demo - C# Tutorial

From the course: Threading in C#

Start my 1-month free trial

Shared resources demo

- [Instructor] Working with threads could be very misleading as threading seems to be deceptively simple, in the beginning at least. What we're going to do is close the solution and then start a new project. We can call it SharedResources. We're going to spawn off a completely new thread. In here, what we can do is just say HelloWorld and what it's going to do is it's going to print HelloWorld. Use Control + Dot and have Visual Studio generate the method for you. In this method, we can say very simply Console.WriteLine. And now, we're going to say Hello World should print only once. Now, if I were to make sure that I have two different threads and I want to print HelloWorld only once and those threads could be two worker threads or one worker thread and one main thread. How do I make that to work? So, if I were to come back to my main thread and call this method, all I have to do is say HelloWorld and that should take care of it. I want this thing to print only once, so as a regular…

Contents