AsyncOperation.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Threading;
  3. using System.Web;
  4. namespace TestMonoWeb
  5. {
  6. class AsynchOperation : IAsyncResult {
  7. private bool _completed;
  8. private Object _state;
  9. private AsyncCallback _callback;
  10. private HttpContext _context;
  11. bool IAsyncResult.IsCompleted { get { return _completed; } }
  12. WaitHandle IAsyncResult.AsyncWaitHandle { get { return null; } }
  13. Object IAsyncResult.AsyncState { get { return _state; } }
  14. bool IAsyncResult.CompletedSynchronously { get { return false; } }
  15. public HttpContext Context {
  16. get {
  17. return _context;
  18. }
  19. }
  20. public AsynchOperation(AsyncCallback callback, HttpContext context, Object state) {
  21. _callback = callback;
  22. _context = context;
  23. _state = state;
  24. _completed = false;
  25. }
  26. public void StartAsyncWork() {
  27. ThreadPool.QueueUserWorkItem(new WaitCallback(DoSomething), null /*workItemState*/);
  28. }
  29. private void DoSomething(Object workItemState) {
  30. // Just for testing..
  31. Thread.Sleep(100);
  32. _completed = true;
  33. _callback(this);
  34. }
  35. }
  36. }