No it isn’t thread safe since it’s equivalent to:
int temp = orig + value;
orig = temp;
You can use Interlocked.Add
instead:
Interlocked.Add(ref orig, value);
More Related Contents:
- WinForm Application UI Hangs during Long-Running Operation
- How can I wait for a thread to finish with .NET?
- Maximum number of threads in a .NET app?
- Is the C# static constructor thread safe?
- Implement C# Generic Timeout
- How to update UI from another thread running in another class
- Attempted to read or write protected memory. This is often an indication that other memory is corrupt
- Compare using Thread.Sleep and Timer for delayed execution
- Is it considered acceptable to not call Dispose() on a TPL Task object?
- Re-entrant locks in C#
- Getting the thread ID from a thread
- Multiple Parallel.ForEach loops in .Net
- What does SynchronizationContext do?
- How to put a task to sleep (or delay) in C# 4.0?
- Task continuation on UI thread
- Is EndInvoke() optional, sort-of optional, or definitely not optional?
- Display progress bar while doing some work in C#?
- Unhandled exceptions in BackgroundWorker
- Run multiple UI Threads
- Multi threading C# application with SQL Server database calls
- ThreadPool.QueueUserWorkItem vs Task.Factory.StartNew
- Do I need to lock or mark as volatile when accessing a simple boolean flag in C#?
- Looking for an example of a custom SynchronizationContext (Required for unit testing)
- I thought await continued on the same thread as the caller, but it seems not to
- What’s the difference between QueueUserWorkItem() and BeginInvoke(), for performing an asynchronous activity with no return types needed
- Why is it a bad practice to lock the object we are going to change?
- Throwing exceptions in callback method for Timers
- How to pause/suspend a thread then continue it?
- Restarting a thread in .NET (using C#)
- Multithreaded NamePipeServer in C#