SqlAsyncResult.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #if NET_2_0
  32. using System;
  33. using System.Threading;
  34. namespace System.Data.SqlClient
  35. {
  36. internal class SqlAsyncResult : IAsyncResult
  37. {
  38. private SqlAsyncState _sqlState;
  39. private WaitHandle _waitHandle;
  40. private bool _completed = false;
  41. private bool _completedSyncly = false;
  42. private bool _ended = false;
  43. private AsyncCallback _userCallback = null;
  44. private object _retValue;
  45. private string _endMethod;
  46. private IAsyncResult _internal;
  47. public SqlAsyncResult (AsyncCallback userCallback, SqlAsyncState sqlState)
  48. {
  49. _sqlState = sqlState;
  50. _userCallback = userCallback;
  51. _waitHandle = new ManualResetEvent (false);
  52. }
  53. public SqlAsyncResult (AsyncCallback userCallback, object state)
  54. {
  55. _sqlState = new SqlAsyncState (state);
  56. _userCallback = userCallback;
  57. _waitHandle = new ManualResetEvent (false);
  58. }
  59. public object AsyncState
  60. {
  61. get { return _sqlState.UserState; }
  62. }
  63. internal SqlAsyncState SqlAsyncState
  64. {
  65. get { return _sqlState; }
  66. }
  67. public WaitHandle AsyncWaitHandle
  68. {
  69. get { return _waitHandle; }
  70. }
  71. public bool IsCompleted
  72. {
  73. get { return _completed; }
  74. }
  75. public bool CompletedSynchronously
  76. {
  77. get { return _completedSyncly; }
  78. }
  79. internal object ReturnValue
  80. {
  81. get { return _retValue; }
  82. set { _retValue = value; }
  83. }
  84. public string EndMethod
  85. {
  86. get { return _endMethod; }
  87. set { _endMethod = value; }
  88. }
  89. public bool Ended
  90. {
  91. get { return _ended; }
  92. set { _ended = value; }
  93. }
  94. internal IAsyncResult InternalResult
  95. {
  96. get { return _internal; }
  97. set { _internal = value; }
  98. }
  99. public AsyncCallback BubbleCallback
  100. {
  101. get { return new AsyncCallback (Bubbleback); }
  102. }
  103. internal void MarkComplete ()
  104. {
  105. _completed = true;
  106. ((ManualResetEvent)_waitHandle).Set ();
  107. if (_userCallback != null)
  108. _userCallback (this);
  109. }
  110. public void Bubbleback (IAsyncResult ar)
  111. {
  112. this.MarkComplete ();
  113. }
  114. }
  115. }
  116. #endif // NET_2_0