2 // System.Data.SqlClient.SqlAsyncResult.cs
5 // T Sureshkumar <tsureshkumar@novell.com>
6 // Ankit Jain <radical@corewars.org>
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Threading;
38 namespace System.Data.SqlClient
40 internal class SqlAsyncResult : IAsyncResult
42 private SqlAsyncState _sqlState;
43 private WaitHandle _waitHandle;
44 private bool _completed = false;
45 private bool _completedSyncly = false;
46 private bool _ended = false;
47 private AsyncCallback _userCallback = null;
48 private object _retValue;
49 private string _endMethod;
50 private IAsyncResult _internal;
52 public SqlAsyncResult (AsyncCallback userCallback, SqlAsyncState sqlState)
55 _userCallback = userCallback;
56 _waitHandle = new ManualResetEvent (false);
59 public SqlAsyncResult (AsyncCallback userCallback, object state)
61 _sqlState = new SqlAsyncState (state);
62 _userCallback = userCallback;
63 _waitHandle = new ManualResetEvent (false);
66 public object AsyncState
68 get { return _sqlState.UserState; }
71 internal SqlAsyncState SqlAsyncState
73 get { return _sqlState; }
76 public WaitHandle AsyncWaitHandle
78 get { return _waitHandle; }
82 public bool IsCompleted
84 get { return _completed; }
87 public bool CompletedSynchronously
89 get { return _completedSyncly; }
92 internal object ReturnValue
94 get { return _retValue; }
95 set { _retValue = value; }
98 public string EndMethod
100 get { return _endMethod; }
101 set { _endMethod = value; }
106 get { return _ended; }
107 set { _ended = value; }
111 internal IAsyncResult InternalResult
113 get { return _internal; }
114 set { _internal = value; }
117 public AsyncCallback BubbleCallback
119 get { return new AsyncCallback (Bubbleback); }
123 internal void MarkComplete ()
126 ((ManualResetEvent)_waitHandle).Set ();
128 if (_userCallback != null)
129 _userCallback (this);
132 public void Bubbleback (IAsyncResult ar)
134 this.MarkComplete ();