Threading Articles

Use ReaderWriterLockSlim to Protect Access to Resources in C#

It is normally safe to allow let multiple threads read data at the same time, but when a thread is required to perform a write, all other threads will need to be blocked. The .NET framework originally provided ReaderWriterLock for this circumstance, but it has performance issues which often outweigh its usefulness. No address this, […]

Read more
Uncategorized

Protect Data on Multiple Processes using C#

If you have a routine which splits data across processors using the Parallel class you may need to protect memory, files or other resources which are shared across the multiple processes. One solution to this is to use a mutex, which is similar to a Monitor object, but at the operating system level. Mutexes must […]

Read more
Uncategorized

Using the Parallel Class in C# – Run Tasks in Parallel on Multiple Processors or Cores

The Parallel Class can be used to split up the tasks which work on the data. For example if you have iterative code that looks like the below code: //6 parts of the book string[] inputTextFiles = { “part1.txt”, “part2.txt”, “part3.txt”, “part4.txt”, “part5.txt”, “part6.txt” }; foreach (string file in inputTextFiles) { string contentStr = File.ReadAllText(file); CountCharacters(contentStr); […]

Read more
Uncategorized

Using the Parallel Class in C# – Processing Data in Parallel across Multiple Processors or Cores

The new Task Parallel Library introduced with .NET 4, allows you to easily split code execution onto multiple processors without using threads or locks. For a task which is easily split into independent sub-tasks, or data that can be partitioned and computed separately you can use the Parallel class in System.Threading to assign tasks to […]

Read more
Uncategorized

Multi Threaded Calculations in C#

Introduction This C# .NET test harness configures easilycomparing throughput results of multi-threaded and single threadedcalculations using ADO .NET datasets. This simple multi-threadedexample performs calculation and database updates three times fasterthan a single threaded approach. Creating the Workspace To start the test harness, open a MicrosoftVisual Studio 2005, .NET Framework Version 2.0 development environmentand create two […]

Read more
Uncategorized

Multithreading Made Easier in C#

* * * Multithreading Made Easier * Created by Anand. * Bihar,India * User: Administrator * Date: 4/3/2005 * Time: 2:36 PM * See how easier its to create multithreadedapplications * Like Java ( I have tried to imitate Java,sRunnable and Thread ) * You have to do just 4 things : * 1)Create a […]

Read more
Uncategorized

Conversion of Singlethreaded C# Class to Multithreaded One

AmThreader_demo.zip   Terms definition Multithreaded class – sounds very confusing. In fact there is no such a thing as singlethreaded or multithreaded class, on the other hand I do not have better name for the construction I have created. Perhaps, I can name it a Thread Isolator.  AmThreader is a code generator that creates a […]

Read more
Uncategorized

Changing the C# Default Limit of 25 Threads of ThreadPool Class

Introduction According to the Microsoft documentation., "The thread pool is created the first time you create an instance of the ThreadPool class. The thread pool has a default limit of 25 threads per available processor, which could be changed using CorSetMaxThreads as defined in the mscoree.h file." It appears to be a simple function call […]

Read more
Uncategorized

.Net Threading, Part II

This is the second article of two partson dotNet threading. In this second part, I will discuss further thesynchronization objects in the System.Threading dotNet namespace, thread localstorage, COM interoperability and thread states. Intermediate Level This article is written for theintermediate and senior C# developer. Working knowledge of the C# programminglanguage and dotNet framework is assumed. […]

Read more
Uncategorized

Use C# Thread Local Storage To Pass Thread Specific Data

In an ideal world developers typically createinstance variables and access these via interfaces to hold threadspecific data. There are times however in a multithreaded applicationwhere this is not realistic due to a variety of factors includinginflexible interfaces, legacy code, and the original overall design ofthe application. The .NET framework provides a mechanism to store dataat […]

Read more
Uncategorized