How to

exchange objects as an atomic operation

Published: 24. October 2011 | Updated: 26. October 2011
License: Microsoft Public License (MS-PL)
Categories: Framework » Threading
Tags: C# Threading
Was this snippet helpful for you? YESYES / NONO

Import namespace

using System.Threading;

Code

var i = 100; // can be double, float, int, IntPtr, long and object

Interlocked.Exchange(ref i, 30);

Console.WriteLine(i);
Console Output:
30
Send us feedback about this snippet »



Related Snippets: