1 namespace System.Web.Mvc.Async { 2 using System; 3 using System.Threading; 4 5 internal sealed class SimpleAsyncResult : IAsyncResult { 6 7 private readonly object _asyncState; 8 private bool _completedSynchronously; 9 private volatile bool _isCompleted; 10 SimpleAsyncResult(object asyncState)11 public SimpleAsyncResult(object asyncState) { 12 _asyncState = asyncState; 13 } 14 15 public object AsyncState { 16 get { 17 return _asyncState; 18 } 19 } 20 21 // ASP.NET IAsyncResult objects should never expose a WaitHandle due to potential deadlocking 22 public WaitHandle AsyncWaitHandle { 23 get { 24 return null; 25 } 26 } 27 28 public bool CompletedSynchronously { 29 get { 30 return _completedSynchronously; 31 } 32 } 33 34 public bool IsCompleted { 35 get { 36 return _isCompleted; 37 } 38 } 39 40 // Proper order of execution: 41 // 1. Set the CompletedSynchronously property to the correct value 42 // 2. Set the IsCompleted flag 43 // 3. Execute the callback 44 // 4. Signal the WaitHandle (which we don't have) MarkCompleted(bool completedSynchronously, AsyncCallback callback)45 public void MarkCompleted(bool completedSynchronously, AsyncCallback callback) { 46 _completedSynchronously = completedSynchronously; 47 _isCompleted = true; 48 49 if (callback != null) { 50 callback(this); 51 } 52 } 53 54 } 55 } 56