1
namespace System
.Web
.Mvc
.Async
{
3 using System
.Threading
;
5 public sealed class OperationCounter
{
11 return Thread
.VolatileRead(ref _count
);
15 public event EventHandler Completed
;
17 private int AddAndExecuteCallbackIfCompleted(int value) {
18 int newCount
= Interlocked
.Add(ref _count
, value);
26 public int Decrement() {
27 return AddAndExecuteCallbackIfCompleted(-1);
30 public int Decrement(int value) {
31 return AddAndExecuteCallbackIfCompleted(-value);
34 public int Increment() {
35 return AddAndExecuteCallbackIfCompleted(1);
38 public int Increment(int value) {
39 return AddAndExecuteCallbackIfCompleted(value);
42 private void OnCompleted() {
43 EventHandler handler
= Completed
;
44 if (handler
!= null) {
45 handler(this, EventArgs
.Empty
);