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.
35 using System.Threading;
37 namespace Mono.Data.Tds.Protocol
39 internal class TdsAsyncResult : IAsyncResult
41 private TdsAsyncState _tdsState;
42 private WaitHandle _waitHandle;
43 private bool _completed = false;
44 private bool _completedSyncly = false;
45 private AsyncCallback _userCallback;
46 private object _retValue;
47 private Exception _exception = null;
49 public TdsAsyncResult (AsyncCallback userCallback, TdsAsyncState tdsState)
52 _userCallback = userCallback;
53 _waitHandle = new ManualResetEvent (false);
56 public TdsAsyncResult (AsyncCallback userCallback, object state)
58 _tdsState = new TdsAsyncState (state);
59 _userCallback = userCallback;
60 _waitHandle = new ManualResetEvent (false);
64 public object AsyncState
66 get { return _tdsState.UserState; }
69 internal TdsAsyncState TdsAsyncState
71 get { return _tdsState; }
74 public WaitHandle AsyncWaitHandle
76 get { return _waitHandle; }
80 public bool IsCompleted
82 get { return _completed; }
85 public bool IsCompletedWithException
87 get { return _exception != null; }
90 public Exception Exception
92 get { return _exception; }
95 public bool CompletedSynchronously
97 get { return _completedSyncly; }
100 internal object ReturnValue
102 get { return _retValue; }
103 set { _retValue = value; }
106 internal void MarkComplete ()
110 ((ManualResetEvent)_waitHandle).Set ();
112 if (_userCallback != null)
113 _userCallback (this);
116 internal void MarkComplete (Exception e)
120 ((ManualResetEvent)_waitHandle).Set ();
122 if (_userCallback != null)
123 _userCallback (this);