Implement MachineKey.Protect and MachineKey.Unprotect
[mono.git] / mcs / class / System.Web.Mvc2 / System.Web.Mvc / Async / SimpleAsyncResult.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\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
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc.Async {\r
14     using System;\r
15     using System.Threading;\r
16 \r
17     internal sealed class SimpleAsyncResult : IAsyncResult {\r
18 \r
19         private readonly object _asyncState;\r
20         private bool _completedSynchronously;\r
21         private volatile bool _isCompleted;\r
22 \r
23         public SimpleAsyncResult(object asyncState) {\r
24             _asyncState = asyncState;\r
25         }\r
26 \r
27         public object AsyncState {\r
28             get {\r
29                 return _asyncState;\r
30             }\r
31         }\r
32 \r
33         // ASP.NET IAsyncResult objects should never expose a WaitHandle due to potential deadlocking\r
34         public WaitHandle AsyncWaitHandle {\r
35             get {\r
36                 return null;\r
37             }\r
38         }\r
39 \r
40         public bool CompletedSynchronously {\r
41             get {\r
42                 return _completedSynchronously;\r
43             }\r
44         }\r
45 \r
46         public bool IsCompleted {\r
47             get {\r
48                 return _isCompleted;\r
49             }\r
50         }\r
51 \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
60 \r
61             if (callback != null) {\r
62                 callback(this);\r
63             }\r
64         }\r
65 \r
66     }\r
67 }\r