在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C#高级教程

C#高级教程

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:1.16M
  • 下载次数:21
  • 浏览次数:264
  • 发布时间:2022-04-27
  • 实例类别:C#语言基础
  • 发 布 人:linhugh
  • 文件格式:.pdf
  • 所需积分:10
 相关标签: C#基础 基础 教程 C#

实例介绍

【实例简介】C#高级教程

【实例截图】

【核心代码】

Table of Contents
Part 1: Getting Started ..................................................................... 4
Introduction and Concepts .............................................................................. 4
Join and Sleep ....................................................................................... 6
How Threading Works ......................................................................... 7
Threads vs Processes ............................................................................ 7
Threading’s Uses and Misuses ............................................................. 8
Creating and Starting Threads ........................................................................ 8
Passing Data to a Thread ...................................................................... 9
Naming Threads ................................................................................. 11
Foreground and Background Threads ................................................ 11
Thread Priority.................................................................................... 12
Exception Handling ............................................................................ 12
Thread Pooling .............................................................................................. 14
Entering the Thread Pool via TPL ...................................................... 15
Entering the Thread Pool Without TPL .............................................. 16
Optimizing the Thread Pool ............................................................... 17
Part 2: Basic Synchronization ....................................................... 19
Synchronization Essentials ........................................................................... 19
Blocking ............................................................................................. 19
Blocking Versus Spinning .................................................................. 20
ThreadState ......................................................................................... 20
Locking ......................................................................................................... 21
Monitor.Enter and Monitor.Exit ......................................................... 22
Choosing the Synchronization Object ................................................ 23
When to Lock ..................................................................................... 23
Locking and Atomicity ....................................................................... 24
Nested Locking ................................................................................... 24
Deadlocks ........................................................................................... 25
Performance ........................................................................................ 26
Mutex .................................................................................................. 26
Semaphore .......................................................................................... 27
© 2006-2010 Joseph Albahari, O’Reilly Media, Inc. All rights reserved. www.albahari.com/threading/ 2
Thread Safety ................................................................................................ 28
Thread Safety and .NET Framework Types ....................................... 28
Thread Safety in Application Servers ................................................. 30
Rich Client Applications and Thread Affinity ................................... 30
Immutable Objects .............................................................................. 32
Signaling with Event Wait Handles .............................................................. 33
AutoResetEvent .................................................................................. 33
ManualResetEvent .............................................................................. 37
CountdownEvent ................................................................................ 38
Creating a Cross-Process EventWaitHandle ...................................... 39
Wait Handles and the Thread Pool ..................................................... 39
WaitAny, WaitAll, and SignalAndWait ............................................. 40
Synchronization Contexts ............................................................................. 41
Reentrancy .......................................................................................... 43
Part 3: Using Threads .................................................................... 44
The Event-Based Asynchronous Pattern ...................................................... 44
BackgroundWorker ....................................................................................... 45
Using BackgroundWorker .................................................................. 45
Subclassing BackgroundWorker ........................................................ 47
Interrupt and Abort ....................................................................................... 48
Interrupt .............................................................................................. 49
Abort ................................................................................................... 49
Safe Cancellation .......................................................................................... 50
Cancellation Tokens ........................................................................... 51
Lazy Initialization ......................................................................................... 52
Lazy<T> ............................................................................................. 53
LazyInitializer..................................................................................... 53
Thread-Local Storage ................................................................................... 54
[ThreadStatic] ..................................................................................... 54
ThreadLocal<T> ................................................................................. 55
GetData and SetData .......................................................................... 55
Timers ........................................................................................................... 56
Multithreaded Timers ......................................................................... 56
Single-Threaded Timers ..................................................................... 58
Part 4: Advanced Topics ............................................................... 59
Nonblocking Synchronization ...................................................................... 59
Memory Barriers and Volatility ......................................................... 59
Interlocked .......................................................................................... 63
Signaling with Wait and Pulse ...................................................................... 65
How to Use Wait and Pulse ................................................................ 65
Producer/Consumer Queue ................................................................. 67
Wait Timeouts .................................................................................... 70
Two-Way Signaling and Races .......................................................... 71
Simulating Wait Handles .................................................................... 72
Writing a CountdownEvent ................................................................ 74
Thread Rendezvous ............................................................................ 75
© 2006-2010 Joseph Albahari, O’Reilly Media, Inc. All rights reserved. www.albahari.com/threading/ 3
The Barrier Class .......................................................................................... 75
Reader/Writer Locks ..................................................................................... 77
Upgradeable Locks and Recursion ..................................................... 78
Suspend and Resume .................................................................................... 80
Aborting Threads .......................................................................................... 80
Complications with Thread.Abort ...................................................... 82
Ending Application Domains ............................................................. 83
Ending Processes ................................................................................ 84
Part 5: Parallel Programming ........................................................ 85
Parallel Programming ................................................................................... 85
Why PFX? .................................................................................................... 85
PFX Concepts ..................................................................................... 86
PFX Components................................................................................ 86
When to Use PFX ............................................................................... 87
PLINQ ........................................................................................................... 87
Parallel Execution Ballistics ............................................................... 89
PLINQ and Ordering .......................................................................... 89
PLINQ Limitations ............................................................................. 90
Example: Parallel Spellchecker .......................................................... 90
Functional Purity ................................................................................ 92
Calling Blocking or I/O-Intensive Functions ..................................... 92
Cancellation ........................................................................................ 94
Optimizing PLINQ ............................................................................. 94
Parallelizing Custom Aggregations .................................................... 96
The Parallel Class ....................................................................................... 100
Parallel.Invoke .................................................................................. 100
Parallel.For and Parallel.ForEach ..................................................... 100
Task Parallelism .......................................................................................... 105
Creating and Starting Tasks .............................................................. 105
Waiting on Tasks .............................................................................. 107
Exception-Handling Tasks ............................................................... 108
Canceling Tasks ................................................................................ 109
Continuations .................................................................................... 110
Task Schedulers and UIs .................................................................. 113
TaskFactory ...................................................................................... 114
TaskCompletionSource .................................................................... 114
Working with AggregateException ............................................................ 115
Flatten and Handle ............................................................................ 116
Concurrent Collections ............................................................................... 117
IProducerConsumerCollection<T> .................................................. 117
ConcurrentBag<T> ........................................................................... 118
BlockingCollection<T> .................................................................... 119
SpinLock and SpinWait .............................................................................. 121
SpinLock........................................................................................... 121
SpinWait ........................................................................................... 122

标签: C#基础 基础 教程 C#

实例下载地址

C#高级教程

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警