MVC3 integrated, with some changes to make it compile on Mono and with Razor2
[mono-project.git] / mcs / class / System.Web.Mvc3 / Mvc / Async / OperationCounter.cs
blob5c8e5e5cfee8da1ec56ca9c92906bc3eff4d1910
1 namespace System.Web.Mvc.Async {
2 using System;
3 using System.Threading;
5 public sealed class OperationCounter {
7 private int _count;
9 public int Count {
10 get {
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);
19 if (newCount == 0) {
20 OnCompleted();
23 return newCount;
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);