C#/.NET Fundamentals Training | C# Tutorial | Threads in C# | Async & Await in C# | C# for Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay let me see if yes ah start my vs code all right okay looks like i'm live let me know guys if you can hear my voice again it is uh as usual a sunday a sunday 4 p.m and let us connect here and let us try to learn something new and today's topic is around uh threads around tpl task parallel library which came in dotnet 4.0 and around the async can await uh you know things out there right now uh why this topic i have chosen you know for this week out here is uh today also i see i see a lot of developers in rubin in the right threading code they use thread.start so i'm really not sure that why uh you know thread.start is used right so my my main goal of this uh so-called as knowledge sharing session is just to try to understand or just to try to put forward you know that what is the difference between a thread what is the difference between tpl the task better library and this new thing called as async and await right uh so yeah so welcome everyone i can see niraj niraj again and and gyan and everyone so i want to put forward you know first this question to everyone out there what do you think what is the difference between a thread and a task so we have system dot threading very quickly i'll resume my share out here so over here you can see we have this system dot threading and we have this system.task right so what is so special about task you know that we can't do with threads uh and uh what is so special about why do we need task thread is all good right so if you if i want to run two functions in parallel if i want to run two code in parallel thread does the work so what is so special about tasks so go ahead put down on the chat that why you think that i should use a tpl or in what scenarios i should use a tpl and in what scenarios i should use uh a task yes and very quickly uh just for everyone's information out here definitely you know i would suggest you know if you are a quest bond member i would suggest to go and watch my shop trading and q a videos which are very much dedicated to threading so here i've just talked about threading what is threading what is lock what is mutex what is semaphore what is semaphore versus sema for what is the difference between a tpl and a task and so on right so i have like four or five hours of session you know which is only dedicated towards uh threading out there but over here now uh you know today the goal is to just quickly understand trading and tpl right okay so i can see some answers out there let me just look into it um tpl is for multi-core that is like hitting the bullseye from shishir from shukla tpr is for multi-core very good uh but okay and then we have jalaj here jalal says that threads are concurrent and the tasks are parallel so okay concurrent and parallel now i don't want to go into that discussion of concurrent and parallel so but i can i can look at um yes so i think you know like july has again put a proper uh what you call a more improvised statement and that makes a lot of sense guys please watch your chat as well in the in the chat you know i'm trying to interact because this is this is youtube right if i put everyone on the microphone we'll all go crazy so uh two answers i can see one from one from jalaj shishir says tpl is for multi-core so it isn't like shisha thread is also for multi-core why not like the whole goal of thread was that i i want to run parallely right and tpl automatically uses code in in multiple cores i think that's the right thing so i'm going to go and copy a jalap's statement out here and set the context of today's session right so i'm going to go and set the context of today's session by by just putting that statement you know from one of our audience out there that tppl automatically uses multi-core uses code in multi-core or uses multiple core what does it mean so here it is let me see if i can draw a diagram out here now the whole goal of thread or tpl is that you want to run the code parallelly you want to run some tasks parallely right so here's how it is so you have let's say your some code out there so you have core one so let's say you have two cores in your machine assume that i'm just for for the understanding purpose you know this is my two core out here right if you say that you want to really run parallely let's say if you have if you have function one which is running on one thread and if you have function two which is running on one thread right let us say that function one is doing some tasks and function two is doing some tasks then function one should actually run over here on this hardware on this score right and when you say function two right and function two should run on this one this is actual parallelism isn't it if this happens that means that you are utilizing your hardwares properly so you know that statement out here that tpl automatically uses multiple codes in other words that both of my functions will run parallely but now you know uh that there can be a situation where if you have a thread affinity i'm just just putting these words out here thread affinity right if if that isn't thread affinity thread affinity means when you go and say new thread and you say thread.start what happens is even though you have two cores out there but because you have a thread affinity towards one core for whatever reason right what happens is both of this function you know try to try to run on the same core so function one runs then after some time the core gives time to function too then function one runs again and then again it gives some type to function too so it it it uh it you know it uh the function one actually uh puts something out the function where the core actually gives time or i'll say this is time slicing okay i'm so sorry i that must be a right word to use your time slicing time slicing means some time to function once sometime to function too then switch the context then again switch the context this one is termed as context switch so that means that when you you know so there are two kinds of things which can happen which your developer is will not be probably be aware of right that one is uh you know you are actually running parallely or you are actually doing time slicing or you are actually doing context switching now if you are doing context switching if this is if this is the condition right then you are not doing parallel programming you as as you know one of our friends said you know concurrent you are concurrent but you are not parallel okay i know that all these words are like together but the point here is that you have one road and all the cars are running on that road if you really want to drive parallelly then you need to have two roads and both the car should run on both the other roads and or else you'll just have a traffic jam out there now when you do threading when you do threading you know this happens time slicing context switching it is your responsibility as a developer to ensure that this thread will run on this score or this thread will run on this score so by default there is a thread affinity when i say thread 1 thread x is equal to new thread and x dot start when i use task parallel library it actually goes and handles this it says that okay like so you have like this much load and you want to run both of these loads in parallel so let me see if core 1 is free i will run over there if core 2 is not free then i will try for core three so tpl has this automatic code again this this sentence is coming from the audience itself and i'm just trying to put more context you know in this session it automatically uses the code in multiple course right so so that's what it is time slicing and or i will say rather uh so it's so the question you have to ask yourself are you doing time slicing or are you doing uh parallel actual parallel processing right now let me go ahead and let me see if there are any questions out there so i can see like so so i can see one of the you know inputs from adam out there task use thread from thread pool to execute job and use low low level thread to execute this job fine so yes what what adam said is absolutely right that task does use threads but task adds extra logic to it so i'm not here to now say that you know task uses threads or not right i'm just trying to say that what a task does and what a thread does not do so you are absolutely right adam that the task internally uses threads right it can use the thread pool it does everything automatically for us but the main thing is that it user like utilizes your hardware so your ravi i said good evening can you change the visual studio code background trim it was not visible clearly okay so yeah we don't worry about the theme i'll try to try to you know it's a black black theme it's a good theme let me let me try to change the theme thread is independent execution of path so that's that's different so i'm sorry i've come down here on the chat and i can see so any questions here guys if you understood this if you have if you understood um this this concept here you know that thread and task so in the sense now what i will do is let me go here let me go and uh resume my share and let me try to do a demo out here so let me try to do a demo i this theme i don't know why the theme is not good out there and what i will do is let me do like this let me do this demo using dot net core and vs code let me try to do this demo using vs code and net core so what i'm going to do is i will go to my e drive out here let me make this display settings let let me make it bigger remember guys this session which i'm taking i'm taking completely on the fly i have really not come prepared as such i know what is a thread what is the task so if some mistakes are happening out here uh please excuse me uh so actually you know 10 minutes before i was writing some code of thread and trying to see if it is working or not but the point here is you know to communicate the actual use of uh task and thread and remember that as we are doing this every sunday right at four o'clock so really i take up a topic you know which comes on the email or it comes from on the on the youtube channel and then i start preparing like at three o'clock so sometimes you know my preparation is really very shallow you can say but i i can tell you that it will definitely help you understand that uh it will definitely help you to understand uh how to go ahead right so so let me let me see that what best i can do and today what i'll do i will not use visual studio so with that you will also get a perspective of how to use vscode.net core right so here it is thread and tpl ok so i'm going to go and copy this let me use vs code let me open up the folder what is so bad about this black theme i can change it i never change this theme i really liked it file preferences i can change this color theme to light visual studio white yeah that's i hope that will help so i'm going to go now and open up the folder and i will just take this folder out here uh let's go ahead and create a simple a task a task code let's go and run some task code let's go and run some tpl code and let us see that it is doing time slicing or it is not doing time slicing right so let us see how we can do this let me see if any other questions out there okay right so i'll come to that i'll come to all the questions guys don't worry i'll come to all of the questions so first thing guys this is dotnet vs code out here and uh you know in visual studio you do a file new project console.net core right but here you need to use this.netcommands.net new console so i'm going to go and create a console library out here you can see that's in console library at the which i've created so i will just go out here now here what we will do is let us use threads so so my goal here is now to demonstrate system.threading so the goal here is to demonstrate that thread does context switching and task parallel library does not do context switching that is a goal out here right so what i will do is i will go ahead i will create a method here let us say static void some heavy task i'm just trying to practice that how it looks to code in vs code so but definitely for big projects i will not be using vs code the luxury the shine of visual studio it is so infatuating i can't leave it really so but uh still uh if i have if you are on mac or if you are on some other os you know then this is the only way to do it so here it is it also has code snippets so i can just use this for yeah so what i'll do is a big loop out here some big loop out here must be a loop inside a loop to just generate some heavy task a bad way of doing it but because just with the task or delay it does not really our thread.delay does not work so you can see i've just made one loop inside another loop right must be i should find out a better way of doing an heavy task so here it is i've just because at the end of the day if you want to if you don't pressurize the cpu you won't really get a good result out there if you just use a simple for loop of 100 it won't do any kind of context switching because the load is very less right so i have you can see here i've just went ahead and i have created a loop out here and i'll just copy paste this so there's some heavy task i1 i2 i3 okay great some heavy task this is doing something out here uh let's let me let me also create some small memory pressure out there by just declaring some variables so i have this some heavy task and what i will do is i'll exact copy of i'll just create some exact copy of some heavy task one as well right so two codes i've written out here exactly same where is it some heavy task ah okay oh when it when you copy it this is so sad you have to copy like this okay fine okay so there it is two methods out here doing some heavy task out here right so i'm going to go and create a thread d1 is equal to new thread let's let's write some sample code the vs code is it's pretty much looks like visual studio now and t2 like right and t1 dot start and t2 dot start yep and i will just put a console.read here so that we don't want this because when the threads will start it will just go ahead and execute both of these tasks and it will just go off right great so you can see here this is an application out here which is having a heavy task and a heavy task one i've just spawned two threads so that means now i will have three threads actually if you if you ask me in this application we will have actually three threads so this is how it will be so in this application one thread you know which will run the static void main the another thread which will run this some heavy task and another thread which will run this some heavy task one three threads right at least my expectation is that this t2 and t1 should run on two different cores now remember guys uh at the end of the day the the task scheduling is very much handled by the operating system the operating system is the king so even though if i try to do a lot of things from here it is very much possible that the operating system depending on the pressure on my computer at this moment depending on a lot of things he can schedule it he can override things and say that no like you all you guys i know that you want to run parallelly but i can't do it for you because the operating system has to be alive first right so operating system gets a top priority so it is possible that when i show this demo sometimes you will see something which is unusual right it is possible but most of the time i think we should see a proper result so now i'm going to go and build this application remember this is vs code and i'm using the dot net cli so i have to say dot net build so there it is it builds it dot net build and there it is so you can see now when i do a net build at the left hand side i can see my bin folders i can see my exe now out there and i can go and now try to run the exe but now what i would like to see out here is i would like to see context switching as i've said that if this is if if if as as i've said that if this thread out here is doing time slicing then the context the number of context switches should increase a lot right so i'm going to go and start open up my perfmon performance monitor i hope everybody is aware of performance monitor performance monitor helps you to track your performance counters performance counters so in your operating system there are lots of performance counters like how much time it took to open your browser how much time it took to get a particular request how much time the garbage collector ran how much time the sql server restarted so a lot of counters are there and you can go and you can track those counters and you can know like if your application is doing good if your computer is doing good and so on right so hordes of contours out there and i won't really go into that and you can see this is the performance counter screen out here so let me go here at this moment at this moment you can see this is the graphical version which it is running out here and it also has how do you say you can you you can see the thing you can see a value as well single value as well so if you don't if you're not a graphical person you want to just watch the values so here it is the processor time but at this moment my interest is not the processor time my interest is context switching of the cpu context switching of the processor right so i'm going to go and remove all these counters out here right click and add guys any questions please put out there once i do this demo i'll come back to questions we can have discussions right so i'll just and the whole goal here is that once you see something visually for example if you see oh this is context switching right it becomes very easy uh to remember the concept right and the most important part is that when i show all these demos out here if you have some issue in production assume that you go in a production somebody says like you know your application is slow right so is it that developers has developer have used only threading and they are not aware of tpl so must be you can go and you can add these counters and see it right so again here it is the as we are doing this tpl versus threads you know these other things also we are learning so i'm going to go now there are lots of counters out here but the one specifically which i discussed um context switching is in system now you must be you must be asking that shift how do you know that this context features per second is in system well because uh there are five or six counters you know which i use to start with like you know the the processor the ram if it is asp.net then the session variables the cache so there are some counters you know which i know in which category they belong because of the habit what i have right so but here this is the system category inside this we have context features per second so i'm going to just take this now remember that already context switching is happening in this computer you know um if you see at this moment that there is a number out there let me go and see a version which is graphical so here it is it's a graphical version out there the value is quite uh because of the scale the value is quite high at this moment what i'll do is i'll go and and and change this to must be a bit low out there so that we can actually see the values okay there it is great so at this moment this is the context switches per second what is happening in my computer i repeat this sentence again this is the context switches per second which is happening in my computer i already talked about context switching right it is all flat it is moving hovering around this 20 thing out here i can just clear it is is uh right it's okay something is happening out there i'm not sure i don't know okay something has gone bad out there what happened what happened okay can you tell me i mean what happened i because i was on zoom voice breaked okay my voice break is it okay let me okay i didn't see the chat out there right okay i i hope that uh i hope that everybody can see my screen right let me see okay strange okay now okay fine okay fine guys i think you know that there was some disturbance out there i'm back again okay uh okay let me where it was where where was i okay here it is guys here it is the contact switches per second which is like approximately it is it is hovering around 20 and must be just going something at the top now if i go and run this application out here so let us see where our application is so our application is here let me go and reveal this in file explorer and let me try to run that exe out here and let us see what happens so let me go out there quite tricky when you're switching when you're switching your windows as well you know the context which has happened so it's very difficult to figure out sometimes when the context features are happening and when not right okay one more thing which i was trying to point here is you can't measure that how much cpu cycle is used by an application you can measure ram i'm just i just want to make an important statement you can you can measure ram you can measure uh what you call memory usage but it is very very difficult to measure processor time i cannot say that okay some 100 cpu cycle has been just running on this because processor is shared right so that's why i'm measuring context switches per second across my computer so you can see now this is what it what it is out here it is it is pretty much now flat so let us let us check that very difficult demo to be shown live frankly guys but let me try my best what i can right and these are the kind of experiments which can help us to understand the application better so it is flat like 20 40 maximum 2040. i'm going to go and run this exe which is compiled out here and just click on this so that's a big huge exe out there which will run and you can see that exe is running and you can see the the context switches has shooted up you can see the number of contact switches has shooted up if you see this this shoot here and then you can see this shoot here this shoot is very abnormal as compared to the previous one so that means that when i'm using threads out there it does context switching right so you can see these two shoots out here i'll just go and close this because i have a pretty very good ram and a good processing power so it just completes those for loop very faster but you can see these two big shoots out here are a clear indication that your contact switches per second increases context switches per second when i say context switches per second i mean context switches per second i can i can go and i can just just take a snip of this so if you see this graph out here uh this one here was very normal till here this this was like you know it was in certain limits it was moving this is the time i started running my exe at the time i run my exe all that thread dot started and the context switches this what you see this graph out here is context switch per second so sometimes that heavy method one runs and then heavy method two runs and then switch heavy method one runs switch every method two runs right context switching if i go and change this code to a tpl if i now go and change this code to a tpl and i'll leave this as a homework to everyone i'll not be showing it here live but you can try this out you can go and you can change this to tpl just the syntaxes are pretty much same so like i can go and say this is task new task so again now guys as as you know one of our friend adam has said out here that task is a is a cover on the thread so it's basically if you see the namespace threading.task there it is right so new task look at the syntaxes almost same out there even that start is just a start just so this is again a task task so go ahead and try this out and then try to run the context switches per second you can see almost the same code out here but this will not show those context switches you won't see those big context features as i have seen now right so i want to go now to the audience out here did we understand what is context switching did we understand how tpl can help us let me know if there are any questions so i'm going to go and first keep that screen out there so take that as a homework guys please take it as a homework so ah because we have other topics to complete but if you go and if you run the run the perfmon it will be the same thing uh okay must be i can just pause the share so let me go back and see the questions hey dj how are you yes okay i can see a question out here sir this perfmon very good question this is a very good question guys please put down your questions i'm open for questions so as we said that task parallel library runs parallel while thread runs time slicing thread runs concurrent thread does context switching right in short in one sentence if i conclude henceforth please use task just a task dot start that's more important right also like one question which has come here and which is very very important i think i should answer this uh uh the question is that how does this work in dot net core perfmon very good question very good question uh so perfmon this perfmon tool what you see out here so let me just go there perfmon tool i'm going i'm let me put this question out here so let me let me try to understand that question what you're saying is perfmon tool is only available in windows absolutely performance counters this tool specifically perfmon it only runs on windows operating system if i am on mac or i am on linux then if i have a net core application how can i track it right so very good good question out there so the net cli right the dot net cli has given us performance counters so here it is what you can do is you can use these two commands out here you know i i knew that this someone is going to ask it actually i was going to go and show the demo by using this then i thought that everybody is so comfortable with perf1 i thought i will start using that right but here it is what you should do is for example now if if you want to go and monitor uh in your uh in in linux or if you want to go and monitor on mac you know then you have to do the following so if you you should run this thread dpl whatever is your exe and you should you should get from there something called as a process id so here it is i'm going to go and run the thread dpl out here and i will go to my task manager and from here now you have to figure out that how do you get the process id from linux right uh so you can see now very quickly uh you will see two exes out here one is you can see this is the console window host so don't take this look at the second one thread tpl three zero four six four in case if you're not seeing this pid please ensure that you select this and you should have the pid out here three zero four six four now what you can do is you can go here you can open up your command prompt and ensure that you have the dotnet cli installed out here and then you can go and you can say your counter what is that number three zero four six four so three zero four six four three zero four six four and remember they have also given lots of events out there by which you can go and you can track so so you can see now it is trying to collect data my goodness look at my look at my fonts i'll just go and make my fonts 20 okay there it is you can see now that's that's by using the dotnet cli out there so i can know garbage collector i can no contact switches i can there are a lot of list of performance counters out here which you can track so you don't have to use the puff one of windows but remember the perch mono windows is very very uh a kind of a tool you know which is useful which is used by the admins so the administrators out there who are working on windows they use that tool a lot but in case if you're a developer who wants to track using your favorite.net tool then this is what it is the gc1 gc0 the thread pool and a lot of other counters if you want to know the list of counters so you can see now this is running if you want to quit from this you can see at the top queue to quit so we can just quit out here there it is and if you want to just know that which are the performance counters which are supported that is the second command out there dot net counter list you can just go and you can fire this and you can know the list of counters which is available at this moment i know that this is not as extensive as what we have in our windows but it is still very good to start with right so that's a the answer for the one question out there how do i track these performance counters are which are non windows right okay let me go back now uh okay okay so let us start the questions here yes absolutely there is sachin okay perf tool yeah i know that every operating system so very good input from sachin here uh saying that so there is a tool called spuf tool absolutely out there and i have not done linux but you know but you what you can do is you can use this.net counter so you are let's say that i don't have knowledge of perf tool i can still use it and just track it in my application right uh okay someone asked me in the interview what is synchronization context wow that synchronization context so there is a question from jalaj here uh what is synchronization called context and let us see some other inputs out here uh task does not do context switching while thread does yes absolutely that's the right sentence out there task the name itself is task parallel library the name is tpl task parallel library it does not do context switching i remember that you know when i was working in dot net 2.0 we have to write so much code to really make it parallel we have to use that uh set uh cpu mask and then we used to say okay like and then and we have to write a lot of code you know first thing i have to i i used to query the cpu saying that okay on this cpu is the antivirus running don't run it there then run run it on the second cpu so we have to go and do a loop find out you know how many cores are there in the machine then we have to go and say set cpu mass 0 0 1 means it will go to the first cpu zero zero zero zero one zero means to the second cpu oh god it was tough this tpl just made our life easy right okay right so okay so here so shishid's question cecilia's question and jalaj's question both of them i will answer in one go i did not come prepared for this but i will try to answer this right the question from shishir and the question from jalaj they are both very much connected together what is synchronization context and why do we use async and await right okay let me go back and switch and uh let us go to our thing here okay resume uh okay on this channel on this channel itself on the quest bond video itself uh you will find that there is one video which is which says the difference between asynchronous and parallel okay let me let me just put down here i don't know how many if you guys have watched that video that that video is very dear to me and we have more two hours of video inside quest 1 videos dedicated to async and parallel right parallel processing parallel and async let me just just let me just talk about this right parallel and async both of them are different i think we had a special lecture on this we had one special lecture where i said that async is not parallel i clearly said that a sync is not parallel right now when i'm using this tpl right when i'm using this tpl i mean parallel means i'm going to go and run two things parallely if you see when people talk about parallel word they use the word worker threads i don't know if you ever ever seen it why they use i i don't like the word worker right right but i can understand why they use the word worker thread which is very much in sync with what we do in real time in real time think about if you have some tasks let us say someone says i want to wash clothes and i want to cook food so what do i say okay like okay these are two parallel tasks they are not connected with each other they are not at all connected with each other there is no exchange of information when you are when you're doing washing you know washing off your clothes it's nothing to do with cooking of the food right there can be something but not really directly right so what you can do you can say okay one worker one person out there he just cooks the food another person dedicated he just goes and uh washes the clothes right both of them are not connected you run super fast you run super fast remember parallel processing when you are actually saying i want to run parallel first thing you should take those tasks which has no connection with each other if you have a if you take a task you know for example you will say okay as the pdf is getting created i want to also go and convert it to word now this is not parallel must be you should say that okay here pdf is getting created and there is some another task out there passing of some file yes both are parallel a good choice of parallel is you know when the two tasks are not connected the time the two start starts exchanging information like this you lose the bear you lose the benefit of parallel processing it is gone right but now fine so we need parallel processing when when then you want to run really super fast right you you are your goal in your head the thing is performance right but now think about you say no like i don't want to really run fast i want to use my cpu to the max so i have this one core out there i want him to do time slicing i want him to do concurrent it's not about fast it's just like i just want to use one worker if i use two worker i have to pay two salaries so for example now let us say if you're saying like you know making tea making making your breakfast in the morning right so you'll say okay i'll first go and put the tea let's say i start to boil it then i say i'll start i'll start you know doing my sandwiches and then i go back and put some milk yes here for this task you know to put two workers out there does not make sense please understand first the concept first thing is in the head if your head is not right then you won't understand why that word async is right so i think what async says is that we here we do not intend to run fast that's not the goal here performance is not the goal here the the here the intent is that we want to just run like this and use that one worker thread in a very optimal way that is what this async is all about so async so he says okay run this async wait now run this async you wait you wait you wait and we complete this only with one processor you want to run fast then you need two processor so parallel and concurrency so this is also termed as concurrency guys please go and see my video on this channel parallel versus concurrency you will understand it right so when you do when you are saying you want to run parallel the technical word in dotnet is tpl when you say you want to run a sync you're going to have only one thread in that one thread he will run these two tasks you get a feel of parallelism please understand you you are a human you get a feel of parallelism okay file is getting downloaded and this is happening right so async and await is concurrent while parallel means too parallel right so i first think you know let me know if this is understood this is the most important part so if i just put if i try to put here this is parallel if i put here this is a sink concurrent here you are using two processors it is it is utilizing resources you are using one processor your performance is the main important thing you are your your main in your head is that i need to be good in performance here it is that i want to use maximum utilize my resources in a proper way not really performance right utilize my course in a proper way right here both of these tasks are very very independent they are completely independent they have to be independent if they are not independent then you again end up into kind of on a sink right here the tasks are correlated there is some connection right something is there where you want to exchange information you want to halt you want to pause like as someone said out there web api so in web api i will post it but you know the client has to get it afterwards so there is a connection of the client and the web api getting posted these are not two things like it is not that the client just shoots it and he goes away no he again waits it now in that case that's why you know if you look at your all your web api has those async and await in the methods right so guys any questions on this concept first thing any query on this thing that parallel versus concurrency parallel versus async if you understand this then other things are easy right so so sushil coming to your question out there like we have you can see that sushi has put a question then i will go to jalaj why do we use async and await in web api because you know in web api the client has to wait the client is not a disconnected thing he has to wait he has to say i will post you and then i have to wait so that means now in in one thread you know he will try to serve the client as well he will try to serve the server as well and he will complete it okay now coming to the synchronization context synchronization context it is very difficult to demo your jalage the synchronization context but the synchronization context what happens is very quickly so so first thing any questions before i move ahead let me not rush any questions on this parallel versus async and uh and concurrency so let me go and point the video out here so parallel versus concurrency okay so all these ads i'm going to go and paste it out here guys there it is that's my that's my video which i posted on the chat which is parallel versus concurrency yeah let me know any questions on the concept all right so now coming to the so i can see that there are no questions out here let's let me wait for a minute you know this youtube is so slow that i i would like to wait and see the questions out there all right right so uh there's there's one more question which has popped up here and let me take up this question the question says that again the same thing synchronization context i think a lot of people are asking for synchronization context let me talk about it synchronization context synchronization context i'm not sure how it is asked in the interviews one i can see question from shishir and another one from mahesh out here what exactly synchronization context so the synchronization context is in connection with a sink so what happens in async as i've said you have a thread running here the thread goes and starts another process in a sync right and it let's say this is a big thread out here which is running for you know whatever like 20 minutes let's say you're not 20 minutes like let's say 60 seconds or whatever right and your thread continues ahead right he continues ahead right now what happens is you know after a certain time this thread says i am done right i am done and he actually tries to ping back now at this moment at this juncture you need to sync up his context you know with this context so what happens here is there is one more small thread spawned up a small thread spawns up you know which takes this context and this context and syncs up and then you move ahead this is termed as the synchronization context so just answering your questions you should out there what exactly synchronization context you can look at my video of my uh tpl versus uh task out there where i've explained you know how the synchronization context works so i've explained with the win form so that that would really help you right so that's the answer out there so async can await i will not show the demo of asynchronous there are lots of videos in this channel itself how to write on a sync and wait code there are lots of codes you know out there but tpl and asynchronous are different fundamentals right so guys let's summarize you know what we have learnt uh let us try to summarize here and if any questions guys please put down out there so from this lesson you know what we can summarize this following first is parallel running and time slicing are two different things time slicing is not really parallel it in this you know only one core is used right time slicing you can say or context switching right second tpl does actual parallel it it implements the automatic parallel for us well that does not happen in threading actually in threading you know by default there is no mechanism of doing automatic parallel so what happens is eventually you will see that the threading has an cpu affinity means it it sticks with one cpu and it just runs on that core or the cpu right fourth we talked about that parallel and async are two different words panel and async are different parallel is mostly for performance while async is mostly you know where you just have one thread and you want to do some sometimes this sometimes this you just want to make the maximum usage of your resources right and then finally we talked about uh synchronization context synchronization context means when the async callback comes back and your main thread is running the synchronization context is a small thread synchronization context is a small thread which spawns up right this it's a thread which connects the callback and the main thread exchanges information so that it can it can merge and it can go together right so these are the takeovers from this class today uh let me know any questions guys before i end the session and very quickly please like go ahead and share this video at the end of the day uh definitely it takes a lot of a lot of thing you know to organize it we have one of our friends out here who actually starts a zoom call he goes and he connects it to youtube i do also do some preparation one hour prior and i come here right i read something uh and i have to show some demos as well so please go ahead and share this please visit the website here question.com uh we have lots of trainings which i'm doing at this moment like every tuesday we are having uh the architecture training what we are doing out there thursday we are having the angular hands on angular with the project rights angular ef core mvc core training thursday and saturday also we do it nbc core right every saturday we are having the az204 rocking training which is happening for azure certification and lots of things you know which we are doing out there so guys let me know any questions here before we uh close this session uh i'll go back to the chat out there and let me see if any questions are there okay should i take care of synchronization context for web api no you don't have to adam you don't have to do anything like they will take care of it they will take care just watch my video of the synchronization context uh it it will take care of it so share if you bought the videos go and watch the threading videos go and watch the async and await videos yes oh from udemy then buy it from my main website sweet marketing right okay okay thank you very much guys and i want i want i would like to know that what can we do for the next sunday what is for the next session give me some inputs a question here from cycad banerjee i will just take this question a sink versus a weight when to use no psyched you have to use both of them in one go async and await are like brothers if you use a sink you have to use a weight if you use a weight you have to use async your program will not compile a sink and await is one concept they are just two key words of shisha so they are they are two brothers they cannot they cannot go apart right so there is no difference you have to use both of them yeah so guys for the next session what we should do please put down on the chat here and uh yeah also versa angular and mvc we have done a lot here now what is happening is we have like around like now almost 90 000 subscribers we are going to go and cross here sometimes i don't get an idea what to do right because there are so many subscribers some have come for machine learning with ml.net some have come for python some have come for mvc some have come from angular some have come from spl server azure uh data structures you know if you see the course out there you know so many codes of course so we sometimes don't know really what we can do best in this channel what small thing we can do let us know what we can do out here as your event hub yep as your event hub okay that's we are doing internal issues so we can do as your event hub but as your event hub you know the whole crowd is very big out here the subscriber list is big i don't know everybody will like azure event hub okay angular or mvc so let me let me take that version angular or mvc but you want it like let me know if it is basic identity i can see from sagar okay i think so that's a good idea raju can you take that question support can you take that from mr gyan here can we discuss the fundamental of entity framework core like code first do some small code out there why not like ef code is very different right let us do that i think okay so i can see a lot of uh points out there but that ef core has caught my eye from from gam percussion out there so i must be i will take the ef core and we always have the next sunday to always take new trainings right thank you very much and please if possible go ahead share this video somewhere on your twitter or on your linkedin who knows like you know next sunday even i will get benefited you know for example in some of the past trainings you know some people gave me some awesome feedbacks which helped me to also learn technically things right so thank you thanks a lot happy sunday thank you
Info
Channel: Questpond
Views: 21,193
Rating: undefined out of 5
Keywords: c# fundamentals, C# training, learn c# for beginners, c# tutorial
Id: j3cNlZM9kgo
Channel Id: undefined
Length: 51min 50sec (3110 seconds)
Published: Sun Aug 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.