C# Multithreading Basics

所在平台: Udemy

课程主页: https://www.udemy.com/course/csharp-multithreading-basics/

课程评论:没有评论

第一个写评论        关注课程

课程简介

C# 多线程基础课程总结 本课程旨在帮助开发者理解和掌握C#中的多线程编程基础,提升应用程序的性能。 **核心问题与解决方案:** * **单线程应用的局限性:** 应用程序的任务按顺序执行,无法同时处理多个任务,导致执行时间长,性能低下。例如,在一个需要比较两个任务执行速度的场景下,单线程必须按顺序执行,即使一个任务很快,也需等待耗时任务完成后才能得到结果。 * **多线程的优势:** 通过同时执行任务,显著缩短执行时间,提高程序响应速度和整体性能。例如,在上述例子中,多线程可以同时运行两个任务,即使耗时任务仍在进行,快速任务也能立即完成。 **课程涵盖的主要技术和概念:** 1. **单线程应用的问题剖析:** 深入分析单线程执行模式带来的效率瓶颈。 2. **C# 多线程模型基础:** 介绍C#中多线程的基本原理。 3. **BackgroundWorker:** 学习使用BackgroundWorker控件在后台执行耗时操作,同时保持UI的响应性。 4. **Dispatcher 结合 UI 更新:** 掌握如何安全地在多线程环境中更新用户界面。 5. **Thread 和 ThreadPool:** 理解Thread和ThreadPool的使用场景及区别,学习如何创建和管理线程。 6. **TPL (Task Parallel Library) - Task.Run 和 Task.Factory:** 介绍Task.Run和Task.Factory,它们是TPL中用于创建和管理任务的强大工具。 7. **TPL - async 和 await:** 学习使用async和await关键字实现异步编程,简化异步操作的管理。 8. **TPL - 并行编程:** 探索Parallel.For和Parallel.ForEach等高级并行处理技术,实现大规模数据的并行计算。 **课程亮点:** * **实际性能对比示例:** 通过一个有趣的实际案例——比较使用字符串(string)和字符串构建器(StringBuilder)进行50,000次字符串拼接的性能差异,直观展示多线程(或更优化的方法)带来的性能提升。 * **实战应用代码:** 课程提供的代码示例可以直接应用于实际项目,帮助开发者快速将所学知识转化为生产力。 本课程虽然侧重于.Net多线程技术的入门,但所介绍的概念和代码对于开发者在实际项目中处理并发和提升性能具有重要的指导意义。

课程评论(0条)

课程详情

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 applicationBasics of mult-threading model of C#The BackgroundWorkerUse Dispatcher to update UI in progressThread and ThreadPoolTPL (1) - Task. Run and Task. FactoryTPL (2) - async and awaitTPL (3) - Parallel programmingAnd 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.

课程标签

0人关注该课程

主题相关的课程