1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
5 * This software is subject to the Microsoft Public License (Ms-PL).
\r
6 * A copy of the license can be found in the license.htm file included
\r
7 * in this distribution.
\r
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc.Async {
\r
15 using System.Threading;
\r
17 internal sealed class SimpleAsyncResult : IAsyncResult {
\r
19 private readonly object _asyncState;
\r
20 private bool _completedSynchronously;
\r
21 private volatile bool _isCompleted;
\r
23 public SimpleAsyncResult(object asyncState) {
\r
24 _asyncState = asyncState;
\r
27 public object AsyncState {
\r
33 // ASP.NET IAsyncResult objects should never expose a WaitHandle due to potential deadlocking
\r
34 public WaitHandle AsyncWaitHandle {
\r
40 public bool CompletedSynchronously {
\r
42 return _completedSynchronously;
\r
46 public bool IsCompleted {
\r
48 return _isCompleted;
\r
52 // Proper order of execution:
\r
53 // 1. Set the CompletedSynchronously property to the correct value
\r
54 // 2. Set the IsCompleted flag
\r
55 // 3. Execute the callback
\r
56 // 4. Signal the WaitHandle (which we don't have)
\r
57 public void MarkCompleted(bool completedSynchronously, AsyncCallback callback) {
\r
58 _completedSynchronously = completedSynchronously;
\r
59 _isCompleted = true;
\r
61 if (callback != null) {
\r