What is the purpose of interlocked class in .NET?

Interlocked class belongs to System.Threading namespace. When two threads try to update same variables or when two threads are concurrently executing there are chances of many error occurrences and incorrect data updation.




In those situations, interlocked class and its methods are very helpful to manipulate on variables accessible by one or more threads without throwing any error or exception. Methods provided by interlocked class are listed below:

Increment - Used to increment a variable’s value and store its result. Int32 and Int64 integers are its legal parameters.
Decrement– Used to decrement a variable’s value and store its result. Int32 and Int64 integers are its legal parameters.
Exchange– Used to exchange values between variables. This method has seven overloaded versions based on the different types it can accept as parameter.
CompareExchange - Compares two variables and stores the result of comparison in another variable. This method also has seven overloaded versions.
Add – Adds two integer variables and updates the result in the first integer variable. It is used to add integers of type Int32 as well as Int64.
Read – Reads an integer variable. It is used to read an integer of type Int64.

_______________________________________________________________________

Add to My Yahoo!


FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

Visit .NET Programming Tutorial Homepage

______________________________________________________

Recommended Resource

| What is Private Access Modifier in C#? | What is Protected Access Modifier in C#? | What is Protected Internal Access Modifier in C#? | What is Public Access Modifier in C#? | What is the difference between virtual and abstract keywords in .NET? | What is the importance of Microsoft Application Blocks in .NET Architecture? | What is the need for Factory Method in C# | What is the purpose of ArrayList in .NET? | What is the purpose of Datareader in ADO.NET? | What is the purpose of Dataset in ADO.NET? | What is the purpose of finally block in C#? | What is the purpose of interlocked class in .NET? | What is the purpose of main() function in C# | What is the purpose of ManualResetEvent in .NET? | What is the purpose of sealed method in C#? | What is the purpose of Thread.Join() method in .NET? | What is the purpose of Thread.Sleep() method in .NET? | What is the purpose of throw keyword in C#? | What is the usage of ENUM in .NET? |


| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2017 - All Rights Reserved.