Merge pull request #1896 from meum/patch-1
[mono.git] / mcs / class / System.Web / Test / TestMonoWeb / AsyncOperation.cs
1 using System;
2 using System.Threading;
3 using System.Web;
4
5 namespace TestMonoWeb
6 {
7         class AsynchOperation : IAsyncResult {
8                 private bool _completed;
9                 private Object _state;
10                 private AsyncCallback _callback;
11                 private HttpContext _context;
12
13                 bool IAsyncResult.IsCompleted { get { return _completed; } }
14                 WaitHandle IAsyncResult.AsyncWaitHandle { get { return null; } }
15                 Object IAsyncResult.AsyncState { get { return _state; } }
16                 bool IAsyncResult.CompletedSynchronously { get { return false; } }
17
18                 public HttpContext Context {
19                         get {
20                                 return _context;
21                         }
22                 }
23
24                 public AsynchOperation(AsyncCallback callback, HttpContext context, Object state) {
25                         _callback = callback;
26                         _context = context;
27                         _state = state;
28                         _completed = false;
29                 }
30
31                 public void StartAsyncWork() {
32                         ThreadPool.QueueUserWorkItem(new WaitCallback(DoSomething), null /*workItemState*/);
33                 }
34
35                 private void DoSomething(Object workItemState) {
36                         // Just for testing..
37                         Thread.Sleep(100);
38                         _completed = true;
39                         try {
40                                 _callback(this);
41                         } catch {}
42                 }
43         }
44 }