Text version of the video
http://csharp-video-tutorials.blogspo...
Slides
http://csharp-video-tutorials.blogspo...
All Dot Net and SQL Server Tutorials
https://www.youtube.com/user/kudvenka...
All C# Text Articles
http://csharp-video-tutorials.blogspo...
All C# Slides
http://csharp-video-tutorials.blogspo...
In this video we will discuss
1. What is a process and a thread
2. Simple multithreading example
Before we discuss multithreading, first let's understand the following terms
1. Process - Process is what the operating system uses to facilitate the execution of a program by providing the resources required. Each process has a unique process Id associated with it. You can view the process within which a program is being executed using windows task manager.
2. Thread - Thread is a light weight process. A process has at least one thread which is commonly called as main thread which actually executes the application code. A single process can have multiple threads.
Please Note: All the threading related classes are present in System.Threading namespace.
Multithreading Example: Create a new windows forms application with 2 buttons and a listbox control and set the following properties.
For the first button control, set
Name = btnTimeConsumingWork
Text = Do Time Consuming Work
For the second button control, set
Name = btnPrintNumbers
Text = Print Numbers
Double click on each of the buttons to generate their respective click event handlers.
For the listbox control, set
Name = listBoxNumbers
Copy and paste the following code in Form1.cs file
using System;
using System.Threading;
using System.Windows.Forms;
namespace ThreadingExample
{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnTimeConsumingWork_Click(object sender, EventArgs e) { btnTimeConsumingWork.Enabled = false; btnPrintNumbers.Enabled = false; DoTimeConsumingWork(); btnTimeConsumingWork.Enabled = true; btnPrintNumbers.Enabled = true; } private void DoTimeConsumingWork() { // Make the thread sleep, to introduce artifical latency Thread.Sleep(5000); } private void btnPrintNumbers_Click(object sender, EventArgs e) { for (int i = 1; i [= 10; i++) { listBoxNumbers.Items.Add(i); } } }
}
1. At this point if we run the program, one thread is automatically created. This thread is called as the Main thread or UI thread. This is the thread that is responsible for doing all the work.
2. Now when you click "Do Time Consuming Work", the first 2 lines of code to disable the button is executed. As a result both the buttons are disabled.
3. DoTimeConsumingWork() method is called next, and at this point the application is unresponsive as it is waiting for the method to complete. Note that the buttons are still disabled and you cannot click on any of them.
4. Finally, once the DoTimeConsumingWork() method completes the buttons are enabled and the application is responsive.
Now change the code in btnTimeConsumingWork_Click() event handler method as shown below.
private void btnTimeConsumingWork_Click(object sender, EventArgs e)
{ btnTimeConsumingWork.Enabled = false; btnPrintNumbers.Enabled = false; // Create another THREAD to offload the work of executing the time consuming method to it. // As a result the UI thread, is free to execute the rest of the code and our application is more responsive. Thread backGroundThread = new Thread(DoTimeConsumingWork); backGroundThread.Start(); //DoTimeConsumingWork(); btnTimeConsumingWork.Enabled = true; btnPrintNumbers.Enabled = true;
}
So one of the benefits of multithreaded programming is that it makes your application more responsive. In our next video, we will discuss the rest of the advantages and disadvantages of multithreaded programming.
examples of idioms Part 86 Multithreading in C# | |
| 935 Likes | 935 Dislikes |
| 255,206 views views | 524K followers |
| Education | Upload TimePublished on 6 Mar 2014 |
Related keywords
asp.net core docker,wcf vs web api,ado.net core,sql server management studio,c#.net versions,webkinz,webadvisor,craigslist nj,wcf one piece,asp.net core 3,ajax players,c#.net core,examples of personification,weber grill parts,webtoon,tutorials by hugo,csharp corner,mvc design pattern,asp.net machine account,servers for minecraft,asp.net core dependency injection,ado.net tutorial,c#.net developer,services angular,ajax ontario,example resume,tutorial definition,tutorial on excel,c#.net online compiler,asp.net mvc tutorial,examples of alliteration,.net framework 4.6.1,asp.net cos'è,.net framework 4.6.2,csharp assembly,tutorialspoint python,sql join,c#.net interview questions,services briefcase,asp.net core web api,ajax jquery,wccftech,craigslist ny,asp.net zero,csharp foreach,server memes,sql date format,services online,chase,examples of culture,c#.net tutorial pdf,serverless architecture,server resume,wcf c#,server books,tutorialspoint javascript,mvcc connect,ado.net mysql,services technologies gps,ajax deadpool,server jobs,cvs,website,mvc tutorial,costco hours,wcf service application,examples of proteins,.net 3.5,tutorialspoint spring,serverless,wcf soap,wcf cat,.net framework 4.5.2,wcf test client,cool math games,services & training hse colombia sas,servicestack,citibank,asp.net core identity,sql union,ajax parking,sql database,asp.net core logging,mvconnect,asp.net guida,cunyfirst,wcf nba,csharp download,wcfi foundation,csharp online,wcf authentication,tutorials near me,c#.net notes pdf,http://asp.net,server 2019,ado.net descargar,web of dreams,chernobyl,serverminer,ajax cleaner,ado.net visual studio 2019,tutorial for windows 10,webassign,ado.net vs entity framework,ado.net visual studio 2017,csharp list,sql like,asp.net mvc,asp.net core tutorial,sqlite,wcfm,ajax roster,tutorial gateway,mvc architecture,http://ado.net,asp.net core mvc,ajax soccer,server hosting,examples of parasitism,wcfi,ajax dish soap,capital one,server rack,tutorialspoint html,csharp interface,craigslist,webroot,tutorialspoint reactjs,ajax request,wcf dragon ball,asp.net core 2.2,tutorialspoint python 3,sql developer,webster,services transmission company sas,sql group by,asp.net core signalr,services manager,mvc framework,ajax paving,mvc near me,examples of irony,examples of figurative language,tutorialspoint spring boot,c#.net framework,c#.net concatenate strings,mvc map,.net framework 4.7.2,csharp online compiler,asp.net download,sql between,ado.net c# pdf,wcf 2019 nba,services tag dell,csharp switch,c#.net mvc,ado.net ventajas y desventajas,csharpstar,wcf tutorial,examples of adjectives,tutorialspoint,ajax meaning,csharp-video-tutorials.blogspot,tutorials dojo,tutorial mission gta online,csharp string format,central park 5,ado.net c#,asp.net core github,server status,ajax fc,server jobs nyc,asp.net core swagger,sql formatter,credit karma,services group,server error in '/' application,.net que es,services windows,asp.net core 3.0,sql injection,wcf ria services,tutorialspoint c#,calculator,c#.net vs asp.net,ado.net entity data model,sql insert,tutorialspoint tableau,services google play apk,sqlyog,asp.net core 3 release date,sql server,c#.net tutorial,server job description,tutorials by a,servicenow,.net framework 4.7,.net core 3,examples of lipids,webcam,.net framework 4.8,mvc hours,.net framework 4.5,.net framework 4.6,c#.net to vb.net,webmd symptom,c#.net w3schools,csharp array,.net framework 4.0,c#.net projects,csharp enum,ajax call,asp.net core 2. guida completa per lo sviluppatore,.net framework 3.5 sp1,asp.net core,server pro,server status ffxiv,c#.net basics,webcrims,cheap flights,asp.net core hosting,services sas,examples of metaphors,tutorialspoint java,tutorialspoint java compiler,examples of adverbs,webmd,.net framework,csharp to json,college football,ado.net dataset,csharp dictionary,tutorial meaning,examples of tone,cnn,website builder,tutorial.mc-complex,tutorialspoint sql,asp.net web api,server side rendering,weber grills,sql server 2017,example synonym,mvc nj,tutorialspoint spark,ado.net oracle,asp.net core download,csharp to vb.net,webster bank,.net framework 3.5,webstaurant,examples of resignation letters,tutorial systems,tutorial teacher,tutorialsystems,ajax post,services fms publish announcement,services.msc no abre,ajax jersey,csharp operator,asp.net core razor pages,server duties,asp.net core environment variables,tutorial on variational autoencoders,csharp random,century 21,examples of carbohydrates,.net framework 3.5 windows 10,c#.net latest version,services consultores,services consulting,mvcsd,mvcsc,services.msc,ado.net pdf,asp.net core configuration,ajax marvel,tutorial synonym,sql update,asp.net tutorial,mvc medical,example of mutualism,ado.net entity data model visual studio 2019,wcfs international curriculum,mvc2,ado.net entity data model visual studio 2017,c#.net tutorialspoint,chase online,wcf api,.net core,costco,server jobs near me,webex,.net framework 2.0,sql meaning,sql tutorial,sql commands,ado.net entity framework,.net framework 4,ajax tavern,example cover letter,tutorialsteacher,ajax javascript,c#.net pdf,c#.net programs,services desk,ajax greek,csharp tutorial,mvc pattern,ado.net sql server,ado.net connection,asp.net identity,mvcu,example of commensalism,.netflix,asp.net core middleware,wcf web service,mvc webadvisor,tutorial music,web store,mvcc,webmail,mvci,mvctc,
Không có nhận xét nào:
Đăng nhận xét