internal IList <object> GetOutParams() { if (!IsCompleted) { AsyncWaitHandle.WaitOne(); } lock (_syncObj) { try { if (_error != null) { throw new UPnPRemoteException(_error); } return(_outParams); } finally { Dispose(); } } }
// End invocation on the delegate in this object. internal Object EndInvoke(Object[] outParams) { // Check for synchronous returns first. lock (this) { if (synchronous) { endInvokeCalled = true; if (resultException != null) { throw resultException; } else { SetOutParams(del, args, outParams); return(result); } } } // Wait for the worker thread to signal us. AsyncWaitHandle.WaitOne(); // Process the return values. lock (this) { endInvokeCalled = true; if (resultException != null) { throw resultException; } else { SetOutParams(del, args, outParams); return(result); } } }
public void WaitEnd() { if (!IsCompleted) { // FIXME: Do we need to use the timeout? If so, what happens when the timeout is reached. // Is the current request cancelled and an exception thrown? If so we need to pass the // exception to the Complete () method and allow the result to complete 'normally'. #if NET_2_1 // neither Moonlight nor MonoTouch supports contexts (WaitOne default to false) bool result = AsyncWaitHandle.WaitOne(Timeout); #else bool result = AsyncWaitHandle.WaitOne(Timeout, true); #endif if (!result) { throw new TimeoutException(); } } if (error != null) { throw error; } }
public void EndInvoke() { // This method assumes that only 1 thread calls EndInvoke // for this object if (!IsCompleted) { // If the operation isn't done, wait for it AsyncWaitHandle.WaitOne(); #if (NETCOREAPP1_0 || NETCOREAPP2_0) AsyncWaitHandle.Dispose(); #else AsyncWaitHandle.Close(); #endif this.asyncWaitHandle = null; // Allow early GC } // Operation is done: if an exception occured, throw it if (this.exception != null) { throw this.exception; } }
public void EndInvoke() { // This method assumes that only 1 thread calls EndInvoke // for this object if (!IsCompleted) { // If the operation isn't done, wait for it AsyncWaitHandle.WaitOne(); AsyncWaitHandle.Close(); m_AsyncWaitHandle = null; // Allow early GC } // Operation is done: if an exception occured, throw it if (m_exception != null) { throw new Exception(String.Format( "{0} was thrown in thread #{1} carrying state ({2}).", m_exception.GetType().FullName, Thread.CurrentThread.ManagedThreadId, m_AsyncState), m_exception); } }
public void EndInvoke() { Log("EndInvoke (enter)"); // This method assumes that only 1 thread calls EndInvoke // for this object if (!IsCompleted) { Log("Waiting on handle..."); // If the operation isn't done, wait for it AsyncWaitHandle.WaitOne(); AsyncWaitHandle.Close(); _resetEvent = null; // Allow early GC } // Operation is done: if an exception occured, throw it if (_exception != null) { Log("Exception encountered: {0}", _exception.Message); throw _exception; } Log("EndInvoke (exit)"); }
public T End() { if (!_isCompleted) { AsyncWaitHandle.WaitOne(); } if (_waitHandle != null) { #if NET_2_0 || NET_3_5 _waitHandle.Close(); #else _waitHandle.Dispose(); #endif _waitHandle = null; } if (_exception != null) { throw _exception; } return(_result); }
public void WaitAndCheckPendingException() { AsyncWaitHandle.WaitOne(); CheckPendingException(); }
/// <devdoc> /// <para> /// Used by the ServicePoint to find a free or new Connection /// for use in making Requests, this is done with the cavet, /// that once a Connection is "locked" it can only be used /// by a specific request. /// /// NOTE: For Whidbey: try to integrate this code into FindConnection() /// </para> /// </devdoc> private Connection FindConnectionAuthenticationGroup(HttpWebRequest request, string connName) { Connection leastBusyConnection = null; GlobalLog.Print("ConnectionGroup::FindConnectionAuthenticationGroup [" + connName + "] for request#" + request.GetHashCode() + ", m_ConnectionList.Count:" + m_ConnectionList.Count.ToString()); // // First try and find a free Connection (i.e. one not busy with Authentication handshake) // or try to find a Request that has already locked a specific Connection, // if a matching Connection is found, then we're done // lock (m_ConnectionList) { Connection matchingConnection; matchingConnection = FindMatchingConnection(request, connName, out leastBusyConnection); if (matchingConnection != null) { matchingConnection.MarkAsReserved(); return(matchingConnection); } if (AuthenticationRequestQueue.Count == 0) { if (leastBusyConnection != null) { if (request.LockConnection) { m_NtlmNegGroup = true; m_IISVersion = leastBusyConnection.IISVersion; } if (request.LockConnection || (m_NtlmNegGroup && !request.Pipelined && request.UnsafeOrProxyAuthenticatedConnectionSharing && m_IISVersion >= 6)) { GlobalLog.Print("Assigning New Locked Request#" + request.GetHashCode().ToString()); leastBusyConnection.LockedRequest = request; } leastBusyConnection.MarkAsReserved(); return(leastBusyConnection); } } else if (leastBusyConnection != null) { AsyncWaitHandle.Set(); } AuthenticationRequestQueue.Enqueue(request); } // // If all the Connections are busy, then we queue ourselves and need to wait. As soon as // one of the Connections are free, we grab the lock, and see if we find ourselves // at the head of the queue. If not, we loop backaround. // Care is taken to examine the request when we wakeup, in case the request is aborted. // while (true) { GlobalLog.Print("waiting"); request.AbortDelegate = m_AbortDelegate; if (!request.Aborted) { AsyncWaitHandle.WaitOne(); } GlobalLog.Print("wait up"); lock (m_ConnectionList) { if (request.Aborted) { PruneAbortedRequests(); // Note that request is not on any connection and it will not be submitted return(null); } FindMatchingConnection(request, connName, out leastBusyConnection); if (AuthenticationRequestQueue.Peek() == request) { GlobalLog.Print("dequeue"); AuthenticationRequestQueue.Dequeue(); if (leastBusyConnection != null) { if (request.LockConnection) { m_NtlmNegGroup = true; m_IISVersion = leastBusyConnection.IISVersion; } if (request.LockConnection || (m_NtlmNegGroup && !request.Pipelined && request.UnsafeOrProxyAuthenticatedConnectionSharing && m_IISVersion >= 6)) { leastBusyConnection.LockedRequest = request; } leastBusyConnection.MarkAsReserved(); return(leastBusyConnection); } AuthenticationRequestQueue.Enqueue(request); } if (leastBusyConnection == null) { AsyncWaitHandle.Reset(); } } } }
/// <devdoc> /// <para> /// Used by the ServicePoint to find a free or new Connection /// for use in making Requests, this is done with the cavet, /// that once a Connection is "locked" it can only be used /// by a specific request. /// /// NOTE: For Whidbey: try to integrate this code into FindConnection() /// </para> /// </devdoc> private Connection FindConnectionAuthenticationGroup(HttpWebRequest request, string connName) { Connection leastBusyConnection = null; GlobalLog.Print("ConnectionGroup::FindConnectionAuthenticationGroup [" + connName + "] m_ConnectionList.Count:" + m_ConnectionList.Count.ToString()); // // First try and find a free Connection (i.e. one not busy with Authentication handshake) // or try to find a Request that has already locked a specific Connection, // if a matching Connection is found, then we're done // lock (m_ConnectionList) { Connection matchingConnection; matchingConnection = FindMatchingConnection(request, connName, out leastBusyConnection); if (matchingConnection != null) { return(matchingConnection); } if (AuthenticationRequestQueue.Count == 0) { if (leastBusyConnection != null) { if (request.LockConnection) { GlobalLog.Print("Assigning New Locked Request#" + request.GetHashCode().ToString()); leastBusyConnection.LockedRequest = request; } return(leastBusyConnection); } } else if (leastBusyConnection != null) { AsyncWaitHandle.Set(); } AuthenticationRequestQueue.Enqueue(request); } // // If all the Connections are busy, then we queue ourselves and need to wait. As soon as // one of the Connections are free, we grab the lock, and see if we find ourselves // at the head of the queue. If not, we loop backaround. // Care is taken to examine the request when we wakeup, in case the request is aborted. // while (true) { GlobalLog.Print("waiting"); request.AbortDelegate = m_AbortDelegate; AsyncWaitHandle.WaitOne(); GlobalLog.Print("wait up"); lock (m_ConnectionList) { if (m_Abort) { PruneAbortedRequests(); } if (request.Aborted) { throw new WebException( NetRes.GetWebStatusString("net_requestaborted", WebExceptionStatus.RequestCanceled), WebExceptionStatus.RequestCanceled); } FindMatchingConnection(request, connName, out leastBusyConnection); if (AuthenticationRequestQueue.Peek() == request) { GlobalLog.Print("dequeue"); AuthenticationRequestQueue.Dequeue(); if (leastBusyConnection != null) { if (request.LockConnection) { leastBusyConnection.LockedRequest = request; } return(leastBusyConnection); } AuthenticationRequestQueue.Enqueue(request); } if (leastBusyConnection == null) { AsyncWaitHandle.Reset(); } } } }