Pro Asynchronous Programming with .NET
Pro Asynchronous Programming with .NET teaches the essential skill of asynchronous programming in .NET. It answers critical questions in .NET application development, such as: how do I keep my program responding at all times to keep my users happy? how do I make the most of the available hardware? h...
Autores principales: | , , |
---|---|
Formato: | Libro electrónico |
Idioma: | Inglés |
Publicado: |
Berkeley, CA :
Apress
2013.
|
Edición: | 1st ed. 2013. |
Colección: | Expert's voice in .NET.
|
Materias: | |
Ver en Biblioteca Universitat Ramon Llull: | https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009629742906719 |
Tabla de Contenidos:
- Cover
- Contents at a Glance
- Contents
- About the Authors
- About the Technical Reviewer
- Acknowledgments
- Chapter 1: An Introduction to Asynchronous Programming
- What Is Asynchronous Programming?
- The Drive to Asynchrony
- Mechanisms for Asynchrony
- Multiple Machines
- Multiple Processes
- Multiple Threads
- Thread Scheduling
- Threads and Resources
- Thread-Specific Resources
- The Stack
- Thread Local Storage
- Registers
- Resources Shared by Threads
- Summary
- Chapter 2: The Evolution of the .NET Asynchronous API
- Asynchrony in the World of .NET 1.0
- System.Threading.Thread
- The Start Method
- Stopping a Thread
- The Abort Method
- The Interrupt Method
- Solving Thread Teardown
- Another Approach: Background Threads
- Coordinating Threads (Join)
- Controlling a Thread's Interaction with COM
- Issues with the Thread Class
- Using the System Thread Pool
- Worker and I/O Threads
- Getting Work on to the Thread Pool
- ThreadPool.QueueUserWorkItem
- Timers
- The APM
- IAsyncResult
- Dealing with Errors
- Accessing Results
- Polling for Completion
- Waiting for Completion
- Completion Notification
- APM in the Framework
- APM and Delegates
- Changes to Async in .NET 1.1
- Asynchrony in .NET 2.0
- Logical and Physical Separation
- Passing Data into a Thread
- Closures
- SynchronizationContext
- Event-Based Asynchronous Pattern
- Error Handling in EAP
- EAP and Cancellation
- Multiple Async Requests
- Minor Changes in .NET 3.5
- Lambda Expressions
- Thread Pool Heuristics in .NET 3.5
- Big Changes in .NET 4.0
- Remodeling the Thread Pool Queue
- Work-Stealing Queues
- Thread Pool Heuristics in .NET 4.0
- Summary
- Chapter 3: Tasks
- What Is a Task ?
- Creating a Compute-Based Task
- Passing Data into a Task
- Dangers of Closures
- Returning Data from a Task.
- Creating I/O-Based Tasks
- Error Handling
- Ignoring Errors
- .NET 4.0
- .NET 4.5
- Designing Task-Based APIs
- Cancellation
- Progress
- Task Relationships
- Chaining Tasks (Continuations)
- Why Use Continuations?
- Nested and Child Tasks
- Why Use Child Tasks?
- Conclusion
- Chapter 4: Basic Thread Safety
- Asynchrony and Data
- It's Not Always Good to Share
- Immutable State
- Atomic State Transition
- Nonatomic State Transition
- Correctness Is Not the Only Problem
- Thread Safety
- The Interlocked Class
- Basic Operations
- Richer Functions
- Interlocked.Exchange
- Interlocked.CompareExchange
- Monitor: The Workhorse of .NET Synchronization
- The lock Keyword
- Timing Out of Monitor Acquisition
- Signaling with Monitors
- Signaling As a Building Block
- Optimizing for Read
- ReaderWriterLock
- Problems with ReaderWriterLock
- ReaderWriterLockSlim
- A Semaphore Out of the Box
- Raising the Starting Gate: ManualResetEventSlim
- CountdownEvent: Simplifying Fork and Join
- Barrier: Rendezvous-Based Synchronization
- Crossing the AppDomain Boundary with WaitHandle
- Mutex
- Semaphore
- Events
- WaitHandle-The Kernel Synchronization Abstraction
- Working with Multiple WaitHandles
- WaitHandle.WaitAll
- WaitHandle.WaitAny
- WaitHandle.SignalAndWait
- Integrating Standard Primitives and Kernel Objects
- Synchronization Is Not the Only Answer
- Conclusion
- Chapter 5: Concurrent Data Structures
- Simplifying Thread Safety
- Lazy
- Concurrent Collections
- ConcurrentDictionary
- Locking Mechanics
- ConcurrentQueue and ConcurrentStack
- ConcurrentBag
- Blocking Collections
- Graceful Shutdown
- Consuming Enumerable
- BlockingCollection of X
- Summary
- Chapter 6: Asynchronous UI
- UI Mechanics
- UI Threading Model
- Synchronization Context
- Send and Post.
- Task Continuations
- Event-Based Asynchronous Pattern (EAP)
- Background Worker
- Data Binding
- Windows Forms
- Windows Presentation Foundation (WPF)
- WinRT
- WPF Dispatcher
- Obtaining the Dispatcher
- Executing Work Through the Dispatcher
- WinRT Dispatcher
- Obtaining the Dispatcher
- Executing Work Through the Dispatcher
- UI Timers
- Windows Forms Timer
- WinRT and WPF Dispatch Timers
- WPF Freezable Components
- Too Much of a Good Thing
- Summary
- Chapter 7: async and await
- Making Asynchronous Programming Simpler
- What Do async and await Actually Do?
- Returning Values from async Methods
- Should You Always Continue on the UI Thread?
- Task.Delay
- Task.WhenAll
- Task.WhenAll, Error Handling
- Task.WhenAny
- async/await Mechanics
- Summary
- Chapter 8: Everything a Task
- TaskCompletionSource
- Worked Example: Creating a Foreground Task
- Unit Testing and Stubbing Asynchronous Methods
- Building Task-Based Combinators
- Improved WhenAny
- Alternative WhenAll, WhenAllOrFail
- Summary
- Chapter 9: Server-Side Async
- Natural Parallelism
- The Problem of I/O
- ASP.NET WebForms
- A Synchronous WebForms Implementation
- Asynchronous Pages in WebForms 4.0
- Mark the Page As Asynchronous
- Registering the Asynchronous Methods
- Implementing the "Begin" Method
- Implementing the "End" Method
- Dealing with Multiple Asynchronous I/O Requests
- Handling Errors in Asynchronous Pages Using APM
- Asynchronous Pages in WebForms 4.5
- ASP.NET MVC
- Asynchronous MVC Processing in .NET 4.0
- Implementing IndexAsync
- Implementing the IndexCompleted Method
- Take Care with APM
- Performing Multiple Async I/O Operations Within an Asynchronous Action
- Asynchronous MVC Processing in .NET 4.5
- ASP.NET Web API
- Asynchronous Web API Operations in .NET 4.0.
- Asynchronous Web API Operations in .NET 4.5
- Windows Communication Foundation
- Asynchronous WCF Services in .NET 4.0
- A Simple Asynchronous Server Operation
- Complex Asynchronous Service Operations
- Error Handling in APM-Based Services
- Asynchronous WCF Services in .NET 4.5
- Summary
- Chapter 10: TPL Dataflow
- The Building Blocks
- Producer and Consumer Revisited
- Linking Blocks
- Transform Block
- Transform Many Block
- Preservation of Order
- Linking to Multiple Targets
- Conditional Linking
- If/else and switch/case
- Recursion
- Shutting Down Gracefully
- Propagating Completion
- Error Handling
- Cancellation
- Glue Blocks
- Buffer Block
- Batch Block
- Broadcast Block
- Joining
- Greedy and Non-greedy Joining
- Asynchronous Blocks
- Summary
- Chapter 11: Parallel Programming
- What Is Driving the Need for Parallelism?
- Coarse- and Fine-Grained Parallelism
- Task and Data-Based Parallelism
- Is It Worth Trying to Parallelize Everything?
- Before You Parallelize
- Parallel Class
- Parallel.Invoke
- Parallel Loops
- Parallel.For
- Beyond the Trade Show Demos
- Parallel.ForEach
- ParallelLoopState
- Nested Loops
- PLINQ
- Moving from Sequential LINQ to PLINQ
- Partitioning
- Does Order Matter?
- Influencing and Configuring the Query
- ForAll
- Aggregating Results
- Summary
- Chapter 12: Task Scheduling
- ConcurrentExclusiveSchedulerPair
- Why Write a Task Scheduler?
- The TaskScheduler Abstraction
- Implementing QueueTask
- Implementing GetScheduledTasks
- Implementing TryExecuteTaskInline
- Executing Tasks
- Implementing a Custom Scheduler
- Creating a Basic Implementation
- Adding Threads on Demand
- Removing Idle Threads
- Unit Testing Custom Schedulers
- Controlling Execution Order with Synchronization Primitives
- Adding Members to the Scheduler to Provide Insight.
- Deriving a Testable Class from the Scheduler
- Summary
- Chapter 13: Debugging Async with Visual Studio
- Types of Multithreading Bugs
- Data Corruption
- Race Conditions
- Deadlocks
- Runaway Threads
- The Limitations of Using Visual Studio for Debugging
- The Interactive Debugger
- It Works on My Machine
- Multithreaded Visual Studio Debugging Basics
- Breakpoints and Threads
- Locals, Autos, and Watch Windows
- The Call Stack Window
- Just My Code
- Improvements in Visual Studio 2013 and Windows 8.1
- The Threads Window
- Flagging and Filtering
- Freezing and Thawing
- Debugging Tasks
- The Parallel Tasks / Tasks Window
- The Parallel Stacks Window
- The Concurrency Visualizer
- Summary
- Chapter 14: Debugging Async -Beyond Visual Studio
- Memory Dumps
- Generating a Memory Dump
- Task Manager
- DebugDiag
- Adding Rules
- Crash
- Performance
- Native (non-.NET) Memory and Handle Leak
- Executing Rules
- ADPLUS
- Crash Mode
- Spawning Mode
- Hang Mode
- Analyzing Memory Dumps
- WinDbg
- SOS
- Loading SOS
- Examining Threads via SOS
- Diagnosing Deadlocks with SOS
- Finding Runaway Threads
- Other Useful SOS Commands
- SOSEX
- Using SOSEX
- Useful SOSEX Commands
- PSSCOR
- Summary
- Index.