CLR multithreading, Part 1

A process is an inner container which has its own virtual address space
Libraries of code are mapped into the address spaces
A thread is path of execution through code within a single process.
For managed threads within an AppDomain
Each thread has it’s own callstack and copy of cpu registers

1. Better cpu utilization when a process runs on multiple core cpu or multiple processors machine.
2. Better support for asynchronous I/O operations. Performing CPU bound operations while waiting to complete I/O bound operations
3. Better UI responsiveness

Context switching overhead

Added program complexity:
1. More lines of code
2. Hard to maintain (readability)
3. Hard to debug
4. Hard to test

CLR thread class name

Thread life time:
Execution continues until thread returns from its entry point.
1. As a result of a standard method return.
2. As result of unhandled exception
1. As an exception caused by the running thread
2. As a result of calling Abort(), Interrupt() methods.

Coordinated thread shut-down
1. User-defined mechanism
2. Requesting thread waits:
2.1 Polling IsAlive
2.2. Calling Thread.Join

Thread Pool
CLR provides per process thread pool
1. Whenever thread is created a few microseconds goes on creating a thread stack and for allocating a memory. Thread pooll cuts overhead by sharing and recycling threads.
2. CLRs pool manager add thread or removes thread from a thread pool on demand.
3. IsBackground property is set to false

When not to use a thread pool
1. When we need foreground thread
2. When we need to set priority to the thread
3. When we run a long running task
4. When we need to identify a thread

Delegates and Async I/O

1. Delegates BeginInvoke queue a request method to the ThreaPool

private int AddMethod(int x)
return (unchecked)i++;

private delegate string OperationMethod(int x);

OperationMethod test = Method;
test.BeginInvoke(0, null, null);

2.1 In case of Async I/O when we call I/O methods such as BeginRead, BeginWrite these methods calls goes to I/O completion port and these methods do not block the thread.
2.2. When Async I/O methods complete only then this call is queued to the ThreadPool.

Suppress Warnings for XML comments


BE shares

Here i will show you, how you can suppress warnings for XML comments after a Visual Studio build.


If you have checked the “XML documentation file” mark in the Visual Studio project settings, a XML file containing all XML comments is created. Additionally you will get a lot of warnings also in designer generated files, because of the missing or wrong XML comments. While sometimes warnings helps us to improve and stabilize our code, getting hundreds of XML comment warnings is just a pain.


Missing XML comment for publicly visible type or member …
XML comment on … has a param tag for ‘…’, but there is no parameter by that name
Parameter ‘…’ has no matching param tag in the XML comment for ‘…’ (but other parameters do)


You can suppress every warning in Visual Studio.

– Right-click the Visual Studio project / Properties / Build…

View original post 12 more words