2 // Mono.Data.Tds.Protocol.TdsAsyncResult.cs
5 // T Sureshkumar <tsureshkumar@novell.com>
6 // Ankit Jain <radical@corewars.org>
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
34 using System.Threading;
36 namespace Mono.Data.Tds.Protocol
38 internal class TdsAsyncResult : IAsyncResult
40 private TdsAsyncState _tdsState;
41 private WaitHandle _waitHandle;
42 private bool _completed = false;
43 private bool _completedSyncly = false;
44 private AsyncCallback _userCallback;
45 private object _retValue;
46 private Exception _exception = null;
48 public TdsAsyncResult (AsyncCallback userCallback, TdsAsyncState tdsState)
51 _userCallback = userCallback;
52 _waitHandle = new ManualResetEvent (false);
55 public TdsAsyncResult (AsyncCallback userCallback, object state)
57 _tdsState = new TdsAsyncState (state);
58 _userCallback = userCallback;
59 _waitHandle = new ManualResetEvent (false);
63 public object AsyncState
65 get { return _tdsState.UserState; }
68 internal TdsAsyncState TdsAsyncState
70 get { return _tdsState; }
73 public WaitHandle AsyncWaitHandle
75 get { return _waitHandle; }
79 public bool IsCompleted
81 get { return _completed; }
84 public bool IsCompletedWithException
86 get { return _exception != null; }
89 public Exception Exception
91 get { return _exception; }
94 public bool CompletedSynchronously
96 get { return _completedSyncly; }
99 internal object ReturnValue
101 get { return _retValue; }
102 set { _retValue = value; }
105 internal void MarkComplete ()
109 ((ManualResetEvent)_waitHandle).Set ();
111 if (_userCallback != null)
112 _userCallback (this);
115 internal void MarkComplete (Exception e)
119 ((ManualResetEvent)_waitHandle).Set ();
121 if (_userCallback != null)
122 _userCallback (this);