mscorlib(4.0.0.0) API with additions
AsyncResult.cs
2 using System.Security;
3 using System.Threading;
4 
6 {
8  [ComVisible(true)]
10  {
11  private IMessageCtrl _mc;
12 
13  private AsyncCallback _acbd;
14 
15  private IMessage _replyMsg;
16 
17  private bool _isCompleted;
18 
19  private bool _endInvokeCalled;
20 
21  private ManualResetEvent _AsyncWaitHandle;
22 
23  private Delegate _asyncDelegate;
24 
25  private object _asyncState;
26 
30  public virtual bool IsCompleted => _isCompleted;
31 
34  public virtual object AsyncDelegate => _asyncDelegate;
35 
38  public virtual object AsyncState => _asyncState;
39 
43  public virtual bool CompletedSynchronously => false;
44 
48  public bool EndInvokeCalled
49  {
50  get
51  {
52  return _endInvokeCalled;
53  }
54  set
55  {
56  _endInvokeCalled = value;
57  }
58  }
59 
62  public virtual WaitHandle AsyncWaitHandle
63  {
64  get
65  {
66  FaultInWaitHandle();
67  return _AsyncWaitHandle;
68  }
69  }
70 
73  public IMessageSink NextSink
74  {
75  [SecurityCritical]
76  get
77  {
78  return null;
79  }
80  }
81 
82  [SecurityCritical]
83  internal AsyncResult(Message m)
84  {
85  m.GetAsyncBeginInfo(out _acbd, out _asyncState);
86  _asyncDelegate = (Delegate)m.GetThisPtr();
87  }
88 
89  private void FaultInWaitHandle()
90  {
91  lock (this)
92  {
93  if (_AsyncWaitHandle == null)
94  {
95  _AsyncWaitHandle = new ManualResetEvent(initialState: false);
96  }
97  }
98  }
99 
102  public virtual void SetMessageCtrl(IMessageCtrl mc)
103  {
104  _mc = mc;
105  }
106 
110  [SecurityCritical]
112  {
113  if (msg == null)
114  {
115  _replyMsg = new ReturnMessage(new RemotingException(Environment.GetResourceString("Remoting_NullMessage")), new ErrorMessage());
116  }
117  else if (!(msg is IMethodReturnMessage))
118  {
119  _replyMsg = new ReturnMessage(new RemotingException(Environment.GetResourceString("Remoting_Message_BadType")), new ErrorMessage());
120  }
121  else
122  {
123  _replyMsg = msg;
124  }
125  _isCompleted = true;
126  FaultInWaitHandle();
127  _AsyncWaitHandle.Set();
128  if (_acbd != null)
129  {
130  _acbd(this);
131  }
132  return null;
133  }
134 
139  [SecurityCritical]
140  public virtual IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
141  {
142  throw new NotSupportedException(Environment.GetResourceString("NotSupported_Method"));
143  }
144 
147  public virtual IMessage GetReplyMessage()
148  {
149  return _replyMsg;
150  }
151  }
152 }
virtual void SetMessageCtrl(IMessageCtrl mc)
Sets an T:System.Runtime.Remoting.Messaging.IMessageCtrl for the current remote method call,...
Definition: AsyncResult.cs:102
Encapsulates operating system–specific objects that wait for exclusive access to shared resources.
Definition: WaitHandle.cs:15
Holds a message returned in response to a method call on a remote object.
IMessageSink NextSink
Gets the next message sink in the sink chain.
Definition: AsyncResult.cs:74
Defines the method call return message interface.
bool Set()
Sets the state of the event to signaled, allowing one or more waiting threads to proceed.
virtual bool CompletedSynchronously
Gets a value indicating whether the BeginInvoke call completed synchronously.
Definition: AsyncResult.cs:43
virtual IMessage GetReplyMessage()
Gets the response message for the asynchronous call.
Definition: AsyncResult.cs:147
Definition: __Canon.cs:3
delegate void AsyncCallback(IAsyncResult ar)
References a method to be called when a corresponding asynchronous operation completes.
virtual bool IsCompleted
Gets a value indicating whether the server has completed the call.
Definition: AsyncResult.cs:30
Provides a way to control asynchronous messages after they have dispatched using the M:System....
Definition: IMessageCtrl.cs:8
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Represents the status of an asynchronous operation.
Definition: IAsyncResult.cs:9
Encapsulates the results of an asynchronous operation on a delegate.
Definition: AsyncResult.cs:9
Notifies one or more waiting threads that an event has occurred. This class cannot be inherited.
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
Definition: Delegate.cs:15
virtual IMessage SyncProcessMessage(IMessage msg)
Synchronously processes a response message returned by a method call on a remote object.
Definition: AsyncResult.cs:111
Contains communication data sent between cooperating message sinks.
Definition: IMessage.cs:9
virtual object AsyncState
Gets the object provided as the last parameter of a BeginInvoke method call.
Definition: AsyncResult.cs:38
virtual WaitHandle AsyncWaitHandle
Gets a T:System.Threading.WaitHandle that encapsulates Win32 synchronization handles,...
Definition: AsyncResult.cs:63
Defines the interface for a message sink.
Definition: IMessageSink.cs:8
virtual object AsyncDelegate
Gets the delegate object on which the asynchronous call was invoked.
Definition: AsyncResult.cs:34
bool EndInvokeCalled
Gets or sets a value indicating whether EndInvoke has been called on the current T:System....
Definition: AsyncResult.cs:49
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
virtual IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
Implements the T:System.Runtime.Remoting.Messaging.IMessageSink interface.
Definition: AsyncResult.cs:140
The exception that is thrown when something has gone wrong during remoting.