This repository has been archived by the owner on May 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy path_AsyncResultState.cs
142 lines (117 loc) · 4.15 KB
/
_AsyncResultState.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace LumiSoft.Net
{
/// <summary>
/// (For internal use only). This class provides holder for IAsyncResult interface and extends it's features.
/// </summary>
internal class AsyncResultState : IAsyncResult
{
private object m_pAsyncObject = null;
private Delegate m_pAsyncDelegate = null;
private AsyncCallback m_pCallback = null;
private object m_pState = null;
private IAsyncResult m_pAsyncResult = null;
private bool m_IsEndCalled = false;
/// <summary>
/// Default constructor.
/// </summary>
/// <param name="asyncObject">Caller's async object.</param>
/// <param name="asyncDelegate">Delegate which is called asynchronously.</param>
/// <param name="callback">Callback to call when the connect operation is complete.</param>
/// <param name="state">User data.</param>
public AsyncResultState(object asyncObject,Delegate asyncDelegate,AsyncCallback callback,object state)
{
m_pAsyncObject = asyncObject;
m_pAsyncDelegate = asyncDelegate;
m_pCallback = callback;
m_pState = state;
}
#region mehtod SetAsyncResult
/// <summary>
/// Sets AsyncResult value.
/// </summary>
/// <param name="asyncResult">Asycnhronous result to wrap.</param>
public void SetAsyncResult(IAsyncResult asyncResult)
{
if(asyncResult == null){
throw new ArgumentNullException("asyncResult");
}
m_pAsyncResult = asyncResult;
}
#endregion
#region method CompletedCallback
/// <summary>
/// This method is called by AsyncDelegate when asynchronous operation completes.
/// </summary>
/// <param name="ar">An IAsyncResult that stores state information and any user defined data for this asynchronous operation.</param>
public void CompletedCallback(IAsyncResult ar)
{
if(m_pCallback != null){
m_pCallback(this);
}
}
#endregion
#region Properties Implementation
/// <summary>
/// Gets or sets caller's async object.
/// </summary>
public object AsyncObject
{
get{ return m_pAsyncObject; }
}
/// <summary>
/// Gets delegate which is called asynchronously.
/// </summary>
public Delegate AsyncDelegate
{
get{ return m_pAsyncDelegate; }
}
/// <summary>
/// Gets source asynchronous result what we wrap.
/// </summary>
public IAsyncResult AsyncResult
{
get{ return m_pAsyncResult; }
}
/// <summary>
/// Gets if the user called the End*() method.
/// </summary>
public bool IsEndCalled
{
get{ return m_IsEndCalled; }
set{ m_IsEndCalled = value; }
}
/// <summary>
/// Gets a user-defined object that qualifies or contains information about an asynchronous operation.
/// </summary>
public object AsyncState
{
get { return m_pState; }
}
/// <summary>
/// Gets a WaitHandle that is used to wait for an asynchronous operation to complete.
/// </summary>
public WaitHandle AsyncWaitHandle
{
get{ return m_pAsyncResult.AsyncWaitHandle; }
}
/// <summary>
/// Gets an indication of whether the asynchronous operation completed synchronously.
/// </summary>
public bool CompletedSynchronously
{
get{ return m_pAsyncResult.CompletedSynchronously; }
}
/// <summary>
/// Gets an indication whether the asynchronous operation has completed.
/// </summary>
public bool IsCompleted
{
get{ return m_pAsyncResult.IsCompleted; }
}
#endregion
}
}