okay so let's talk threading it's one of those buzzword gets a lot of people excited it's actually pretty straightforward if you've done any programming at all you've done some threaded programming I say that a little bit factiously because uh whenever you start a program it starts a single thread of execution so if I had F10 here in Visual Studio we see the program counter here this yellow marker that the debuger displaying it shows the next statement which is set up to execute and really a curly brace is not a statement but it's just a placeholder
for the debugger right now there's the thread we call the main thread and it uh starts here in Main and we'll travel all the way until it hits this closing curly right here so not very exciting but yes it is threaded programming it's a single thread and if you're single child in a single child household you'll know that uh you don't have to share anything with your siblings it's quite nice but the problem with threading arises when there's several threads and then there's toys that they want to share or data exactly that they need to
share anyway uh this example is not very exciting let's do something a little more more interesting I'm going to make a second thread first of all let's at least get something printing on the console I'm going to console right line my name my name I bet you thought I was going to write Jamie uh control F5 run this you see nothing really exciting happening there um let's put it in a different function static void different did I say function uh I'm GNA say method method function method it's all the same U I'm going to take
this print statement put it down here um and now uh if I run it you know the main thread will start here in main the designers of the C language could have called this method anything they decid to call it main probably based off C and whoever decided that main was a great name um but it could be named anything in fact on a CLR level you can name your entry points whatever you want but we won't get into that um let's make a new thread bar thread gets new thread um this is in the
system. threading name space and it takes uh a delegate uh the delegate type is parameterize thread start or I can do thread start I'll get to parameterize thread start a little bit later but if I type thread start here and then F12 with the cursor on thread start we see it's a delegate returns void takes no arguments I hope you're familiar and comfortable with delegates if not please go see the delegate videos okay so since it takes a delegate that returns void takes no arguments well that matches the signature right here so I can uh
let me just copy this I can paste that method right there uh and then if I run it notice no output okay we instantiated a thread object but we did not actually create the thread to create the thread I have to say start all right so now it's almost like we have two entry points of execution we have the the one that we're familiar with the main one here that looks a little bit like a piece of thread doesn't it and then when I make a thread on different method that will actually create another thread
that will begin its execution right here uh and then go through different method now this is not a very complicated method obviously but uh hopefully you see the point that that main thread it starts on this cly this other thread starts here there's really no difference other other than that between the two threads we have going on so I'm going to hit F10 we'll create the thread we'll start the thread notice our program counters here if we look at the output there's no output quite yet if I had F10 the debugger will uh stop because
execution completed and my console window left I'm actually going to to hit contrl F5 to uh pull the debugger away you see now my name prints because we allowed this thread to execute now and the console window just didn't disappear okay okay now in later videos I'll show you how to debug these threads and things but I can let me F9 uh maybe if I get my lock turned on let's try that again F9 why am I not getting a break point I'll just click out here and get a break point I hit F5 come
on F5 ah and now you see that R in this second thread we actually broke on this line here all right so don't make it more complicated than it needs to be there's one thread up here started this second thread and the second thread went down through here so that's a basic hello world of threads uh in future videos we're going to get into a lot more sexier stuff