SqlAsyncResult.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // System.Data.SqlClient.SqlAsyncResult.cs
  3. //
  4. // Author:
  5. // T Sureshkumar <[email protected]>
  6. // Ankit Jain <[email protected]>
  7. //
  8. //
  9. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System;
  32. using System.Threading;
  33. namespace System.Data.SqlClient
  34. {
  35. internal class SqlAsyncResult : IAsyncResult
  36. {
  37. private SqlAsyncState _sqlState;
  38. private WaitHandle _waitHandle;
  39. private bool _completed = false;
  40. private bool _completedSyncly = false;
  41. private bool _ended = false;
  42. private AsyncCallback _userCallback = null;
  43. private object _retValue;
  44. private string _endMethod;
  45. private IAsyncResult _internal;
  46. public SqlAsyncResult (AsyncCallback userCallback, SqlAsyncState sqlState)
  47. {
  48. _sqlState = sqlState;
  49. _userCallback = userCallback;
  50. _waitHandle = new ManualResetEvent (false);
  51. }
  52. public SqlAsyncResult (AsyncCallback userCallback, object state)
  53. {
  54. _sqlState = new SqlAsyncState (state);
  55. _userCallback = userCallback;
  56. _waitHandle = new ManualResetEvent (false);
  57. }
  58. public object AsyncState
  59. {
  60. get { return _sqlState.UserState; }
  61. }
  62. internal SqlAsyncState SqlAsyncState
  63. {
  64. get { return _sqlState; }
  65. }
  66. public WaitHandle AsyncWaitHandle
  67. {
  68. get { return _waitHandle; }
  69. }
  70. public bool IsCompleted
  71. {
  72. get { return _completed; }
  73. }
  74. public bool CompletedSynchronously
  75. {
  76. get { return _completedSyncly; }
  77. }
  78. internal object ReturnValue
  79. {
  80. get { return _retValue; }
  81. set { _retValue = value; }
  82. }
  83. public string EndMethod
  84. {
  85. get { return _endMethod; }
  86. set { _endMethod = value; }
  87. }
  88. public bool Ended
  89. {
  90. get { return _ended; }
  91. set { _ended = value; }
  92. }
  93. internal IAsyncResult InternalResult
  94. {
  95. get { return _internal; }
  96. set { _internal = value; }
  97. }
  98. public AsyncCallback BubbleCallback
  99. {
  100. get { return new AsyncCallback (Bubbleback); }
  101. }
  102. internal void MarkComplete ()
  103. {
  104. _completed = true;
  105. ((ManualResetEvent)_waitHandle).Set ();
  106. if (_userCallback != null)
  107. _userCallback (this);
  108. }
  109. public void Bubbleback (IAsyncResult ar)
  110. {
  111. this.MarkComplete ();
  112. }
  113. }
  114. }