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
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Understanding threading2m 55s
-
(Locked)
Context switching7m 12s
-
(Locked)
Thread naming2m 33s
-
(Locked)
Shared resources2m 52s
-
(Locked)
Shared resources demo7m 35s
-
(Locked)
Threads vs. processes1m 1s
-
(Locked)
Local memory2m 50s
-
(Locked)
Thread pool2m 41s
-
(Locked)
Thread pool demo9m 49s
-
(Locked)
Other threading concepts3m 27s
-
(Locked)
Exception handling4m 37s
-
-
-
-