Leanpub Header

Skip to main content

.NET 本事-非同步程式設計

閱讀本書,學習基礎至進階的非同步 API,並了解一些常犯的錯誤以及建議寫法,讓你寫出高效能、回應速度快、與高延展性的應用程式。

Minimum price

$7.99

$9.50

You pay

$9.50
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
243
Readers
102
Pages
About

About

About the Book

(本書目前為 alpha 版,內容仍在持續更新)

這本書的目標是讓讀者了解:

  • 非同步呼叫與執行緒等相關基礎概念。
  • .NET 平台目前主流的非同步程式 API,包括 TPL 與 C# 的 async 與 await 語法(舊的 API 與寫法僅簡單帶過)。
  • 非同步呼叫的建議寫法,以及如何避免一些常犯的錯誤。
  • 撰寫多執行緒應用程式時,經常需要用到的同步化技巧。
  • 其他實用的 API。

Share this book

Author

About the Author

Michael Tsai

Hi there! I'm a technical writer with 10+ years of experience in software development and 16 awards of Microsoft .NET MVP.

著作:《C# 本事》、《.NET 本事:非同步程式設計》、《.NET 相依性注入》(簡體中文版:.NET 依賴注入)

譯作: 軟體構築美學 (Brownfield Application Development in .NET)、物件導向分析設計與應用(Object-Oriented Analysis and Design with Applications 3rd Edition)、軟體工程與 Microsoft Visual Studio Team System.

部落格: https://www.huanlintalk.com

Contents

Table of Contents

關於本書

  1. 誰適合閱讀本書
  2. 在何處購買
  3. 書寫慣例
  4. 本書用到的工具
  5. 範例程式與補充資料
  6. 版本更新紀錄

關於作者

1.從零開始

  1. 1.1話說從頭:處理序與執行緒
  2. 1.2執行緒帶來的負擔
  3. 1.2.1Context Switch
  4. 1.3爭先恐後-關於優先順序
  5. 1.3.1處理序的優先順序
  6. 1.3.2執行緒的優先順序
  7. 1.4並行、平行、非同步
  8. 1.5本章回顧

2..NET 非同步 API 概覽

  1. 2.1專屬執行緒
  2. 2.1.1建立與啟動執行緒
  3. 2.1.2等待與暫停執行緒
  4. 2.1.3共享變數
  5. 2.1.4執行緒同步化
  6. 2.1.5前景執行緒 vs. 背景執行緒
  7. 2.1.6使用專屬執行緒的時機
  8. 2.2執行緒集區
  9. 2.2.1執行緒集區的運作方式
  10. 2.2.2工作執行緒與 I/O 執行緒
  11. 2.2.3使用執行緒集區
  12. 2.3非同步程式設計模型(APM)
  13. 2.4基於事件的非同步模式(EAP)
  14. 2.5基於工作的非同步模式(TAP)
  15. 2.5.1工作平行程式庫(TPL)
  16. 2.5.2建立與起始非同步工作
  17. 2.6非同步程式設計
  18. 2.7重點回顧

3.async 與 await 基礎

  1. 3.1基礎觀念:控制流
  2. 3.2Hello, async / await
  3. 3.2.1範例:同步呼叫
  4. 3.2.2範例:非同步呼叫
  5. 3.3關鍵字 asyncawait 的作用
  6. 3.4避免使用 async void
  7. 3.5Async Main 方法
  8. 3.6觀察執行緒切換過程
  9. 3.7我的程式當掉了?!
  10. 3.7.1SynchronizationContext
  11. 3.7.2鎖死的原因與解法
  12. 3.7.3Windows Forms 程式鎖死的範例
  13. 3.8重點回顧

4.非同步程式設計常用技巧

  1. 4.1非同步方法的各種樣貌
  2. 4.1.1非同步介面方法
  3. 4.1.2非同步屬性?
  4. 4.1.3非同步建構函式?
  5. 4.1.4非同步 Lambda
  6. 4.2非同步延遲
  7. 4.2.1重試機制
  8. 4.3傳回已完成的工作
  9. 4.3.1不要 await Task.FromResult()
  10. 4.4等待工作完成
  11. 4.4.1等待一組工作完成
  12. 4.4.2等待任意一個工作完成
  13. 4.5取消工作
  14. 4.6工作的延續
  15. 4.6.1串接與組合多項工作
  16. 4.6.2TaskContinuationOptions
  17. 4.6.3取消「中間的」延續工作
  18. 4.7混合使用同步與非同步方法
  19. 4.7.1在非同步方法中呼叫同步方法
  20. 4.7.2在同步方法中呼叫非同步方法
  21. 4.7.3不要寫假的 async 方法
  22. 4.8進度回報
  23. 4.9錯誤處理
  24. 4.10為非同步方法撰寫單元測試
  25. 4.11重點回顧

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

About the Publisher

About the Publisher

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub