C# Tutorial 16 Threads


Get the Code Here :
Best C# Book :
Support me on Patreon :

In this part of my C# tutorial I’ll cover threads in depth. With threads you can execute multiple pieces of code that share resources and data without corrupting it. I cover a simple thread example, sleep, a more advanced with lock, Priority, and how to pass data to a thread.

For best results take notes on the cheat sheet provided above as you watch and leave any questions you have.

Thank you to Patreon supporters like the following for helping me make this video

jaryd remillard : instagram: @distant_admiration
jaryd remillard :


Xem Thêm Bài Viết Khác:https://wijstaanvooronzegrondrechten.org/cong-nghe


  1. I've a question,
    If the thread number 2 tries to acces into the lock statement while any other thread is executing the same lock statement, the thread number 2 would wait until the other one gets out of the statement or until the other thread is died.

  2. Hi Derek !

    im trying to use Thread for disabling my UI buttons while an operation is execting (button click to start it) .can you help me .

  3. Hi Derek. I've removed the lock statement from this code, and balance does not go below 0 when I execute the code. It looks like lock doesn't do anything in this example. Please explain. Thank you.

  4. Rhodium

    Great tutorial, but when I run the last example I'm getting an output of 1-10, 1-5, 1-6 in order. Do you know if anything might have been updated since you made this video?

    Thank you

  5. Locks will block other threads from executing the code contained in the lock block. The threads will have to wait until the thread inside the lock block has completed and the lock is released. This does have a negative impact on performance in a multithreaded environment. If you do need to do this you should make sure the code within the lock block can process very quickly. You should try to avoid expensive activities like accessing a database etc.

  6. honestly , i didn't understand why using the lock , you didn't provide an accurate example , i don't understand what is it doing spcial , couldn't you do that with ( else {} ) ?

  7. can someone explain the private Object acctLock = new object(); to me i don't understand. Was this explained in another video?

  8. Thanks for the video. Sounds like you like the VS shortcuts (cw for Console.Writeline), and noticed that you were writing out for loops manually. You can do a shortcut for a lot of things with the tab tab including for, while, if, etc. My personal favorite is switch statement for an enum: if you put the enum in the switch parameter and hit enter, it auto fills your entire case block. HUGE time saver.

  9. Hey is it possible to use threads to run in the background to capture serial data real-time in a c# wpf application??? I'm asking as I'm experimenting with a xbee radio and I can only get data in my application to capture serial data once when executing.


Please enter your comment!
Please enter your name here