C# Multithreading Basics
What you'll learn
- Learn concepts of different threading models
- Learn how to avoid UI being blocked by codes
- Run tasks in background using BackgroundWorkers
- Update data to UI using Dispatcher and Data binding
- Run tasks in multiple threads using Thread class
- Run tasks in multiple threads using Task class
- Run tasks asynchronously using async and await
- Run lots of tasks concurrently using Parallel programming
- Basic C# programming knowledge
- Want to boost you application with the power of multi-threading
I think that most of us programmers start developing applications in single threaded mode. Which means that tasks or actions defined in this application will be executed in a certain predefined sequence. But at some point, we need to start tasks simultaneously and to be completed asynchronously in order to save execution time and to boost up performance.
Here is an example. You need to compare the execution speed of two tasks. In a single threaded program you have to perform the speed measurement tasks one after another, then compare the time difference at the end of when both tasks are done. Let’s say Task A needs 30 seconds and Task B needs only 0.5 second. Therefore, if you start Task B after Task A, you won’t see Task B to be completed until Task A is finished.
If we do it in a multithreaded mode, then no matter which task first, we can always see Task B to be finished in 0.5 second while Task A is still running. And if we use the right multi-threading technique, Task A might not even need 30 seconds to run. This is the beauty of multi-threading programming.
For the time being, there are several multi-threading techniques available in C# and .Net. Including Thread, ThreadPool, Task, TaskFactory, Task Run, BackgroundWorker, async and await, Parallel.For/Parallel.ForEach… Wow! So overwhelming!
Don’t worry, this two-hour long course provides you a very good insight on when to use what. Topics that will be mainly covered including the followings:
Problems with single threaded application
Basics of mult-threading model of C#
Use Dispatcher to update UI in progress
Thread and ThreadPool
TPL (1) - Task. Run and Task. Factory
TPL (2) - async and await
TPL (3) - Parallel programming
And the sample being used in this course is quite interesting as well. We are going to compare the speed of concatenating a string 50,000 times by using a string type variable and a StringBuilder type variable, respectively. You will be surprised at the performance that they yield.
Even though this course just brings you the basic concept of .Net’s multithreading techniques, the codes introduced in this course should be useful enough in your real world projects. Hope you enjoy this course.
Who this course is for:
- Any C# developer who wants to have a clear concept of multi-threading
Hello everyone, my name is Tom Liao. I'm the tutor of this course, and glad to meet you guys here.
I’m a Microsoft certified system engineer with more than 20 years experience developing all kinds of applications such as web based ERP systems, client/server applications, video streaming applications, file encryption applications as well as AI recognition applications, for large corporations or government departments, and most of them were developed in C#.
I have integrated and transformed all those project experiences into concepts and hands-on exercises in this course. So, by completing this course, not only can you learn the concept and theory of C# programming, but you can also avoid all the mistakes that I have been through to save your valuable time and focus on the right track.
I’m also a PMI certified project management and agile management professional who has practiced agile software development on many of my projects in recent years. I’m not going to teach agile methodology in this course, but you can still see how I introduce my lectures in the agile way.
The other thing I would like to talk about is how I became a programmer. When I was twenty-something, I was a financial auditor. I felt very stupid to work very long hour overtime on all kinds of paperwork. So I designed many Excel VBA programs trying to simplify my work. By doing so, I found myself highly interested in coding, and very soon I found that VBA programs can no longer satisfy my desire to learn programming. So, I decided to switch my career from accounting to programming. I have spent a lot of my leisure time learning how to code by reading all kinds of books, attending classes, and building whatever I have learned into applications that can apply to my job. And a couple of years later, I finally made my dream come true, I got my MBA in MIS degree from University of Dallas in Texas, United States and then started to work as a webmaster in my professor's company. I have officially become a programmer since then. And this was how I started VB and C# programming.
Therefore, if you don't have any official programming training but want to learn, or even want to be in the IT field, then you have come to the right place. If I can do it, then you can do it too, just let me lead the way. But if you do have an IT background, that’s even better, I can boost your coding skill to the real world level.