* (star), 756
. (dot) operators, 871
access
code, 884
members, referent types, 871–872
runtime, 883
thread-safe, 815
adding event handlers, 846–848
agents, execution, 881
AggregateException,
757–764, 768
asynchronous Web requests, 779
parallel loop exception handling, 798–800
algorithms
hill climbing, 798
mark-and-sweep-based, 882
work stealing, 798
allocating
data on call stacks, 868
virtual memory, 851
AllocExecutionBlock()
method, 855
antecedent tasks, 753
APIs (application programming interfaces)
parameters, 192
APM (Asynchronous Programming Model), 908–921
AppDomain, 762
applicable, 193
applications
domains, 887
instances, formatting single, 829–830
virtual, 872
applying
StructLayoutAttribute,
853
Task.Factory.StartNew()
method, 769
arguments, named, 191
AsParallel()
method, 584
assemblies
versioning, 889
async
keyword, 777–781, 937–942
asynchronous delegate invocation, 921–924
asynchronous programming
high-latency operations, invoking, 772–777
Task-based Asynchronous Pattern (TAP), 770–794
task-based asynchrony, 848–849
atomic operation, 829
attributes, customizing, 893
automatically shimmed interfaces, 848
avoiding
synchronization with MethodImplAttribute,
823
await
keyword, 777–781, 937–942
background worker patterns, 928–932
BCL (Base Class Library), 885, 892, 894
BeginGetResponse()
method, 908
BeginX()
method, 908
behaviors, dynamic objects, 716–718
binding
late, 893
methods, 714
runtime, XML elements, 719–720
Break()
method, 803
breaking parallel loops, 803–804
buffers, overrun, 883
bugs, runtime performance, 885–886
C language pointers, declaring, 865
C++ language, 890
deterministic destruction, 882
pointers, declaring, 865
calling
P/Invoke
APIs, 861
stacks, 868
Task.ContinueWith
method, 752, 789
Cancel()
method, 766
CancellationToken
class, 764, 767
CancellationTokenSource
class, 767
cancelling
parallel loops, 800
PLINQ queries, 807
CAS (code access security), 884
catch
clause, 779
change()
method, 942
checking types, 883
CIL (Common Intermediate Language), 876, 877, 894
CLI, 890
machine code, compilation to, 879–880
circumventing encapsulation, 883
classes
CancellationTokenSource,
767
concurrent collections, 835–837
CountdownEvent,
835
IProducerConsumer-Collection<T>,
835
Monitor,
thread synchronization, 817–819
ParallelQuery<T>,
806
Semaphore,
835
SemaphoreSlim,
835
System.Exception,
433
System.Lazy<T>,
420
System.Net.WebRequest,
908
System.Threading,
812
System.Threading.AutoReset-Event,
semaphores, 834
System.Threading.Interlocked,
824–826
System.Threading.ManualResetEvent,
831–834
System.Threading.ManualResetEventSlim,
831–834
System.Threading.Mutex,
829–830
System.Threading.WaitHandle,
831
TaskCompletionSource<T>,
784
TaskScheduler,
788
Task<T>,
779
polling, 749
ThreadLocal<T>,
838
ThreadStaticAttribute,
839
Tuple,
461
clauses, catch,
779
cleanup, resources (APM), 914
CLI (Common Language Infrastructure), 894
application domains, 887
BCL, 892
CIL, 890
CTS, 891
CLR (Common Language Runtime), 881, 894
CLS (Common Language Specification), 877, 891–892, 895
COBOL, 890
code
access security, 884
managed, 881
unsafe, 845–846, 863–864, 867, 872–873
collections, concurrency, 835–837
COM (Component Object Model)
DLL registration, 890
STAThreadAttribute
class, 842–843
commands, xcopy,
889
compilers, 878
paths, configuring, 898
compiling
just-in-time compilation, 879
static compilation vs. dynamic programming, 720–721
compression, 882
computers, guest, 872
configuring
background worker patterns, 930–931
compiler paths, 898
consoles, synchronization, 920–921
Console.WriteLine()
method, 871
context, synchronization, 788–790
continuation, tasks, 789
ContinueWith()
method, 753, 775, 919–920
contravariance, enabling, 485–488
control flow
asynchronous tasks, 751
tasks, 780
conversions
CIL, 879
types, checking, 883
cooperative cancellation, 764
CountdownEvent
class, 835
covariance
CPS (continuation passing style), 911–913, 915
CPUs (central processing units), running LINQ queries in parallel, 584
Create()
method, 461
CTS (Common Type System), 877, 891, 895
customizing
attributes, 893
methods, asynchronous, 783–786
synchronization contexts, 790
data
managed, 881
types
dynamic,
716
de-allocating objects, 882
declaring
Decrement()
method, 814, 821, 825
delegates
asynchronous delegate invocation, 921–924
P/Invoke, 862
synchronous, 747
System.Func/System.Action,
514–530
unsafe code, executing via, 872–873
deleting event handlers, 846–848
deployment, xcopy, 889
dereferencing pointers, 869–871
deterministic destruction, 882
development, 886
device drivers, 886
diagrams, CancellationToken
class, 767
DirectoryCountLines()
method, 191
dirty space, 882
disabling parallelism, 802
Dispose()
method, tasks, 770
distribution, APM parameters, 911
DLL (Dynamic Link Library), COM registration, 890
domains, applications, 887
DoStuffAsync()
method, 787
dot (.
) operator, 871
DotGNU, 878
drivers, devices, 886
dynamic objects
static compilation vs., 720–721
EAP (Event-based Asynchronous Pattern), 924–927
elements, runtime binding, 719–720
enabling
encapsulation
circumventing, 883
encryption, strings, 804
EndGetResponse()
method, 908
EndX()
method, 908
enums, TaskContinuation-Options,
754–755
error handling, platform interoperability/unsafe code, 854–856
events
handlers
notifications, multiple threads, 826–827
exceptions
AggregateException,
757–764, 768
asynchronous Web requests, 779
parallel loop exception handling, 798–800
handling
asynchronous high-latency operations, 775–776
background worker patterns, 931–932
InnerExceptions
property, 760
NullReferenceException,
826
OperationCanceledException,
807
OutOfMemoryException,
433
reporting, 433
StackOverflowException,
433
System.ComponentModel.Win32Exception,
854
TaskCanceledException,
767, 768
execution
agents, 881
delegates, unsafe code, 872–873
loops, iterations in parallel, 794–804
managed, 881
pseudocode, 814
VES, 895
expressions, lambda
asynchronous programming, 782–783
lazy loading, 420
external functions
factory methods, 461
FCL (Framework Class Library), 892, 895
fields, declaring as volatile
, 823–824
files
references, assemblies, 889
finalizers, WaitHandle,
770
ForEach()
method, 801
formatting single instance applications, 829–830
FORTRAN, 890
Framework (Microsoft .NET), 878
frameworks, 877
FromCurrentSynchronizationContext()
method, 788
functionality, CLI, 888n5
functions
external
pointers, 862
garbage collection
gating parallelism, 802
general-purpose delegates, System.Func/System.Action,
514–530
generics
lazy loading, 420
GetDynamicMemberNames()
method, 724
GetEnumerator()
method, 787n8
GetResponse()
method, 772
GetResponseAsync()
method, 779
guest computers, 872
guidelines
covariance, 489
delegates, types, 515
locking, avoiding, 823
long-running tasks, 770
managed wrappers/unmanaged methods, 856
multiple type parameters, 460
multithreading, unhandled exceptions, 764
P/Invoke, 862
parallel loops, 797
synchronization, avoiding, 823
thread synchronization design, 829
Handle()
method, 760
handlers, events
handling
errors, platform interoperability/unsafe code, 854–856
exceptions
asynchronous high-latency operations, 775–776
background worker patterns, 931–932
high-latency operations, invoking, 771–777
hill climbing, 798
hot tasks, 748
IAsyncAction<T>
interface, 848, 849
IDisposable
interface, tasks, 770
IDispose()
method, 915
ILMerge
utility, 889
immutable strings, modifying, 869–870
implementing
dynamic objects, 714
Increment()
method, 825
InnerExceptions
property, 760
instances, formatting single, 829–830
interfaces
automatically shimmed, 848
IDisposable
, 770
IReadOnlyPair<T>,
484
multithreading, prior to TPL and C# 5.0, 907–936
PairInitializer<T>,
487
parameters, 192
interoperability
CIL, 890
Invoke()
method, 932
InvokeRequired
property, 932
invoking
asynchronous
high-latency operations, 771–777
reflection, dynamic objects, 714–716
IProducerConsumer-Collection<T>
class, 835
IReadOnlyPair<T>
interface, 484
IsCancellationRequested
property, 766, 767, 801
IsCompleted
property, 750, 804
iterations
long-running loops, 802
jitting, 879
Join()
method, 748
just-in-time compilation, 879
keywords, 5
lock
string,
avoiding locking, 822–823
this,
avoiding locking, 822–823
lambda expressions
asynchronous programming, 782–783
lazy loading, 420
languages
CIL, 876
CLR, 881
COBOL, 890
FORTRAN, 890
source, 890
late binding, 893
latency, invoking high-latency operations, 771–777
libraries
Task Parallel Library (TPL), 790
LINQ queries, running in parallel, 584–585, 804–808
Linux, installing platforms, 898
listings
APM patterns
accessing user interfaces, 933–934
asynchronous delegate invocation, 922–923
background worker patterns, 928–929
ContinueWith()
method, 919
invoking user interface objects, 935–936
invoking with callback/state, 911–912
System.Net.WebRequest
class, 908–909
delegates
declaring Func/Action,
514–515
dynamic objects
generics
arity, 460
combining covariance and contravariance, 487
compiler validation of variance, 488
contravariance, 486
covariance using out
type parameter modifier, 484
Create()
method, 461
multiple type parameters, 460
methods
specifying parameters by names, 191–192
multithreading
applying Task.Factory.StartNew()
method, 769
asynchronous Web requests, 773–774, 777–778
calling Task.ContinueWith
method, 752, 789
cancelling parallel loops, 800–801
cancelling PLINQ queries, 807–808
customizing asynchronous methods, 784–786
handling tasks, unhandled exceptions, 758–759
invoking asynchronous tasks, 747–748
iterating over await
operations, 792–793
LINQ Select()
method, 804
observing unhandled exceptions, 760–761
parallel execution of foreach
loops, 797
PLINQ Select()
method, 805
PLINQ with query expressions, 806
polling Task<T>
classes, 749
registering for notifications, 756
registering for unhandled exceptions, 762–763
synchronous high-latency invocation with WPF, 791–792
synchronous Web requests, 772–773
unhandled exception handling, parallel iterations, 799
platform interoperability/unsafe code
accessing referent type members, 871–872
allocating data on call stacks, 868
applying ref/out
rather than pointers, 852
declaring external methods, 849–850
declaring types, 853
designating unsafe code, 863, 872–873
invalid referent types, 866
modifying immutable strings, 869–870
wrapping APIs, 861
reflection, dynamic programming using, 715
standard query operators, executing LINQ queries in parallel, 584
System.Threading.Timer
class, 941–942
System.Timers.Timer
class, 939–940
thread synchronization
creating single instance applications, 829–830
firing event notifications, 826
lock
keyword, 820
System.Threading.Interlocked
class, 824–825
Task.Delay()
method, 842
thread-safe event notification, 826
ThreadLocal<T>
class, 838
ThreadStaticAttribute
class, 839–840
unsynchronized local variables, 815–816
unsynchronized state, 813
Tic-Tac-Toe
source code, 901–905
well-formed types, lazy loading properties, 420
local storage, threads, 837–841
local variables, multiple threads, 815–816
lock
keyword
consoles, synchronization, 920–921
lockTaken
parameter, 819
long-running
loops, 802
loops
executing, iterations in parallel, 794–804
parallel
executing iterations in, 794–804
LowestBreakIteration
property, 804
machine code, 876
Main()
method, 821
managed code, 881
managed data, 881
managed execution, 881
mark-and-sweep-based algorithms, 882
members
dynamic objects, overriding, 723–724
referent types, accessing, 871–872
memory, allocating virtual, 851
metadata, 877
MethodImplAttribute,
avoiding with synchronization, 823
methods
AllocExecutionBlock(),
855
AsParallel(),
584
asynchronous, customizing, 783–786
BeginGetResponse(),
908
BeginX(),
908
binding, 714
Break(),
803
Cancel(),
766
change(),
942
ContinueWith(),
753, 775, 919–920
Create(),
461
DirectoryCountLines(),
191
Dispose(),
770
DoStuffAsync(),
787
EAP, 925
EndGetResponse(),
908
EndX(),
908
factory, 461
ForEach(),
801
FromCurrentSynchronizationContext(),
788
GetDynamicMemberNames(),
724
GetEnumerator(),
787n8
GetResponse(),
772
GetResponseAsync(),
779
Handle(),
760
IDispose(),
915
Increment(),
825
Invoke(),
932
Join(),
748
Main(),
821
Monitor.Enter(),
818
Monitor.Exit(),
818
person.NonExistentMethodCallStillCompiles (),
717
PiCalculator.Calculate(),
749
Ping.Send(),
791
ProcessKill(),
785
Pulse(),
819
ReadToEnd(),
772
ReadToEndAsync(),
775
Reset(),
834
Run(),
748
Select(),
804
SendTaskAsync(),
792
StartX(),
908
Stop(),
803
Task.ContinueWith(),
793
Task.ContinueWith,
calling, 752, 789
Task.Delay(),
843
Task.Factory(),
768
Task.Factory.StartNew(),
769
ThrowIfCancellationRequested(),
768
TryGetMember(),
723
TrySetMember(),
723
Wait(),
750
WaitAll(),
831
WaitAny(),
831
WaitForExit(),
784
WebRequest.GetResponseAsync(),
774
WriteWebRequestSizeAsync(),
779
Microsoft
ILMerge
utility, 889
compilers, 878
platform portability, 885, 886
Silverlight, 878
XNA, 878
mind maps
CLI infrastructure, 875
platform interoperability/unsafe code, 845
thread synchronization, 811
models
asynchronous programming, 908–921
COM, STAThreadAttribute
class, 842–843
modifiers
access, runtime, 883
volatile,
declaring fields as, 823–824
modifying immutable strings, 869–870
Monitor
class, synchronization, 817–819
Monitor.Enter()
method, 818
Monitor.Exit()
method, 818
multiple threads
multithreading
interfaces, prior to TPL and C# 5.0, 907–936
LINQ queries, running in parallel, 804–808
loops, executing iterations in parallel, 794–804
Task-based Asynchronous Pattern (TAP), 770–794
tasks
named arguments, 191
.NET (Microsoft), 894, 897–899
compilers, 878
platform portability, 885, 886
notifications
events, multiple threads, 826–827
registering for, 756
NullReferenceException,
826
objects
COM, STAThreadAttribute
class, 842–843
de-allocating, 882
deterministic destruction, 882
lock
keyword, selecting, 821–822
observer patterns, 846
OperationCanceledException,
807
operators, dot (.), 871
options
TaskCreationOptions.LongRunning,
798
OutOfMemoryException,
433
overloading types, applying arity, 460
overriding members, dynamic objects, 723–724
overrun, buffers, 883
P/Invoke (Platform Invoke), 849–862
API calls with wrappers, 861–86–
external functions, calling, 858–861
guidelines, 862
PairInitializer<T>
interface, 487
Parallel.For()
method, 795, 803
parallelism
disabling, 802
LINQ queries, running in, 804–808
loops
executing iterations in, 794–804
ParallelOptions
parameter, 802
ParallelOptions
type, 801
ParallelQuery<T>
class, 806
parameters
distribution, APM, 911
lockTaken,
819
ParallelOptions,
802
types
passing
paths, configuring compilers, 898
patterns
async/await,
timers prior to, 937–942
observer, 846
token cancellation, 801
performance
synchronization, 828
Task Parallel Library (TPL), 798
person.NonExistentMethodCallStillCompiles ()
method, 717
PiCalculator.Calculate()
method, 749
Ping.Send()
method, 791
platforms
PLINQ (Parallel LINQ), 804–808
functions, 862
polling
cancellation tasks, 766
Task<T>
classes, 749
pools, threading, 746
portability of platforms, 884–885
principles, dynamic objects, 716–718
ProcessKill()
method, 785
programming
programs, Tic-Tac-Toe,
901–905
properties
InnerExceptions,
760
InvokeRequired,
932
IsCancellationRequested,
766, 767, 801
LowestBreakIteration,
804
pseudocode execution, 814
Pulse()
method, 819
queries, running LINQ in parallel, 584–585, 804–808
ReadToEnd()
method, 772
ReadToEndAsync()
method, 775
reentrant deadlocks, 828
references
files, assemblies, 889
pointers, declaring, 864
referent types, accessing members, 871–872
reflection, 883
dynamic objects, invoking, 714–716
metadata, 893
registering
COM DLL, 890
for notifications, 756
remoting, 921
removing event handlers, 846–848
reporting exceptions, 433
requests
cancellation, 768
Reset()
method, 834
resources, cleanup (APM), 914
rethrowing exceptions, 433
Rotor, 878
Run()
method, 748
running LINQ queries in parallel, 584–585, 804–808
runtime
CLR, 894
WinRT, 895
XML elements, binding, 719–720
safety, types, 883
schedulers, tasks, 746, 788–790
security, code access, 884
Select()
method, 804
selecting objects, lock
keyword, 821–822
Semaphore
class, 835
semaphores, System.Threading.AutoResetEvent
class, 834
SemaphoreSlim
class, 835
SendTaskAsync()
method, 792
ServiceStatus,
865
Silverlight (Microsoft), 878
single instance applications, formatting, 829–830
Smalltalk, 890
software, virtual, 872
source code, Tic-Tac-Toe,
901–905
source languages, 890
spaces, dirty, 882
stackalloc
data, 868
StackOverflowException,
433
stacks, calling, 868
standard query operators, running LINQ queries in parallel, 584–585
star (*), 756
StartX()
method, 908
statements
Console.WriteLine(),
871
string.join,
796
STAThreadAttribute
class, 842–843
static compilation vs. dynamic programming, 720–721
Stop()
method, 803
storing local threads, 837–841
string
keyword, avoiding locking, 822–823
string.join
statement, 796
strings
encryption, 804
StructLayoutAttribute,
853
structural equality, delegates, 516–517
switches, unsafe,
864
synchronization
delegates, 747
operations, invoking high-latency, 771–772
applying lock
keywords, 819–821
avoiding with MethodImplAttribute,
823
declaring fields as volatile,
823–824
design best practices, 827–829
selecting lock
objects, 821–822
System.Threading.Interlocked
class, 824–826
System.Action
delegate, 514–530
System.AsyncCallback
class, 911–913
System.ComponentModel.Win32Exception
method, 854
System.Exception
class, 433
System.Lazy<T>
class, 420
System.Net.WebRequest
class, 908
System.Threading
class, 812
System.Threading.AutoResetEvent
class, semaphores, 834
System.Threading.Interlocked
class, 824–826
System.Threading.ManualResetEvent
class, 831–834
System.Threading.ManualResetEventSlim
class, 831–834
System.Threading.Mutex
class, 829–830
System.Threading.WaitHandle
class, 831
T
type parameter, 461
tables
compilers, 878
concurrent collection classes, 836–837
control flow within tasks, 780
keywords, 5
ManualResetEvent
synchronization, 833
sample pseudocode execution, 814
System.Threading.Interlocked
class, 825
TaskContinuationOptions
enums, 754–755
TAP (Task-based Asynchronous Pattern)
APM methods, 920
task-based asynchrony, 848–849
TaskCanceledException,
767, 768
TaskCompletionSource<T>
class, 784
TaskContinuationOptions
enums, 754–755
Task.ContinueWith()
method, 752, 789, 793
TaskCreationOptions.LongRunning
option, 798
Task.Delay()
method, 843
Task.Factory()
method, 768
Task.Factory.StartNew()
method, 769
tasks
antecedent, 753
control flow, 780
IDisposable
interface, 770
TaskScheduler
class, 788
Task<T>
class, 779
polling, 749
this
keyword, avoiding locking, 822–823
thread-safe, 815
event notification, 826
threading
multiple threads, local variables, 815–816
pools, 746
applying lock
keywords, 819–821
avoiding with MethodImplAttribute,
823
declaring fields as volatile,
823–824
design best practices, 827–829
selecting lock
objects, 821–822
System.Threading.Interlocked
class, 824–826
ThreadLocal<T>
class, 838
ThreadStaticAttribute
class, 839
ThrowIfCancellationRequested()
method, 768
Tic-Tac-Toe
source code, 901–905
timers
prior to async/await
patterns, 937–942
token cancellation, 801
TPL (Task Parallel Library), 790
interfaces, multithreading prior to C# 5.0, 907–936
performance, 798
TryGetMember()
method, 723
TrySetMember()
method, 723
Tuple
class, 461
typeof
keyword, avoiding locking, 822–823
types
checking, 883
CTS, 891
overloading, applying arity, 460
ParallelOptions,
801
parameters
referent, accessing members, 871–872
safety, 883
thread synchronization, 829–837
unmanaged, 864
UIs (user interfaces), Windows, 790–792, 932–936
unhandled exceptions, threading, 761–764
unmanaged types, 864
unsafe code, 845–846, 863–864, 867
delegates, executing via, 872–873
unsafe covariance in arrays, support, 488–489
utilities, ILMerge,
889
versioning assemblies, 889
VES (Virtual Execution System), 876, 877, 881, 895
virtual memory, 851
virtual software, 872
volatile
modifier, declaring fields as, 823–824
vulnerabilities, buffer overruns, 883
Wait()
method, 750
WaitAll()
method, 831
WaitAny()
method, 831
WaitForExit()
method, 784
WaitHandle
finalizer, 770
WebRequest.GetResponseAsync()
method, 774
Win32, error handling, 854–855
Windows
UIs (user interfaces), 790–792, 932–936
WinRT (Windows Runtime), 845, 895
work stealing, 798
WPF (Windows Presentation Foundation), 934–936
wrappers, APIs (P/Invoke), 861–86–
WriteWebRequestSizeAsync()
method, 779
xcopy deployment, 889
XML (Extensible Markup Language) elements, runtime binding, 719–720
XNA (Microsoft), 878
18.222.114.132