当前位置: 首页>>代码示例>>C#>>正文


C# IAsyncResult.GetType方法代码示例

本文整理汇总了C#中IAsyncResult.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IAsyncResult.GetType方法的具体用法?C# IAsyncResult.GetType怎么用?C# IAsyncResult.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAsyncResult的用法示例。


在下文中一共展示了IAsyncResult.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EndShutdown

		internal void EndShutdown (IAsyncResult asyncResult)
		{
			if (asyncResult == null)
				throw new ArgumentNullException ("asyncResult");

			var shutdownResult = asyncResult as ShutdownAsyncResult;
			if (shutdownResult == null)
				throw new ArgumentException (SR.GetString (SR.net_io_async_result, asyncResult.GetType ().FullName), "asyncResult");

			if (shutdownResult.SentShutdown)
				SecureStream.EndShutdown (shutdownResult);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:12,代码来源:_SslState.cs

示例2: EndExecute

 /// <summary>
 /// В конце асинхронной операции надо убедиться, что она завершена,
 /// и если нужно, обработать исключения
 /// </summary>
 /// <param name="asyncResult">состояние асинхронной операции в виде <see cref="IAsyncResult" /></param>
 /// <returns>Результат выполнения асинхронной операции. В нашем случае это
 /// Task.Result для <see cref="Task{TResult}" /> и Task.Wait() для <see cref="Task" /></returns>
 public override object EndExecute(IAsyncResult asyncResult)
 {
     // TODO: надо что-то тут сделать с асинхронными эксепшнами
     return
         _taskValueExtractors.GetOrAdd(asyncResult.GetType(), createTaskValueExtractor)(asyncResult);
 }
开发者ID:eugeneagafonov,项目名称:ConferenceDemos,代码行数:13,代码来源:TaskAsyncActionDescriptor.cs

示例3: ValidateAsyncResult

		internal void ValidateAsyncResult (IAsyncResult ar, string endMethod)
		{
			if (ar == null)
				throw new ArgumentException ("result passed is null!");
			if (! (ar is SqlAsyncResult))
				throw new ArgumentException (String.Format ("cannot test validity of types {0}",
					ar.GetType ()));
			SqlAsyncResult result = (SqlAsyncResult) ar;
			if (result.EndMethod != endMethod)
				throw new InvalidOperationException (String.Format ("Mismatched {0} called for AsyncResult. " + 
					"Expected call to {1} but {0} is called instead.",
					endMethod, result.EndMethod));
			if (result.Ended)
				throw new InvalidOperationException (String.Format ("The method {0} cannot be called " + 
					"more than once for the same AsyncResult.", endMethod));
		}
开发者ID:nlhepler,项目名称:mono,代码行数:16,代码来源:SqlCommand.cs

示例4: ReadFrameComplete

        // IO COMPLETION CALLBACK
        //
        // This callback is responsible for getting the complete protocol frame.
        // 1. it reads the header.
        // 2. it determines the frame size.
        // 3. loops while not all frame received or an error.
        //
        private void ReadFrameComplete(IAsyncResult transportResult)
        {
            do
            {
                if (!(transportResult.AsyncState is WorkerAsyncResult))
                {
                    if (GlobalLog.IsEnabled)
                    {
                        GlobalLog.AssertFormat("StreamFramer::ReadFrameComplete|The state expected to be WorkerAsyncResult, received:{0}.", transportResult.GetType().FullName);
                    }

                    Debug.Fail("StreamFramer::ReadFrameComplete|The state expected to be WorkerAsyncResult, received:" + transportResult.GetType().FullName + ".");
                }

                WorkerAsyncResult workerResult = (WorkerAsyncResult)transportResult.AsyncState;

                int bytesRead = _transport.EndRead(transportResult);
                workerResult.Offset += bytesRead;

                if (!(workerResult.Offset <= workerResult.End))
                {
                    if (GlobalLog.IsEnabled)
                    {
                        GlobalLog.AssertFormat("StreamFramer::ReadFrameCallback|WRONG: offset - end = {0}", workerResult.Offset - workerResult.End);
                    }

                    Debug.Fail("StreamFramer::ReadFrameCallback|WRONG: offset - end = " + (workerResult.Offset - workerResult.End));
                }

                if (bytesRead <= 0)
                {
                    // (by design) This indicates the stream has receives EOF
                    // If we are in the middle of a Frame - fail, otherwise - produce EOF
                    object result = null;
                    if (!workerResult.HeaderDone && workerResult.Offset == 0)
                    {
                        result = (object)-1;
                    }
                    else
                    {
                        result = new System.IO.IOException(SR.net_frame_read_io);
                    }

                    workerResult.InvokeCallback(result);
                    return;
                }

                if (workerResult.Offset >= workerResult.End)
                {
                    if (!workerResult.HeaderDone)
                    {
                        workerResult.HeaderDone = true;
                        // This indicates the header has been read successfully
                        _curReadHeader.CopyFrom(workerResult.Buffer, 0, _readVerifier);
                        int payloadSize = _curReadHeader.PayloadSize;
                        if (payloadSize < 0)
                        {
                            // Let's call user callback and he call us back and we will throw
                            workerResult.InvokeCallback(new System.IO.IOException(SR.Format(SR.net_frame_read_size)));
                        }

                        if (payloadSize == 0)
                        {
                            // report empty frame (NOT eof!) to the caller, he might be interested in
                            workerResult.InvokeCallback(0);
                            return;
                        }

                        if (payloadSize > _curReadHeader.MaxMessageSize)
                        {
                            throw new InvalidOperationException(SR.Format(SR.net_frame_size,
                                                                            _curReadHeader.MaxMessageSize.ToString(NumberFormatInfo.InvariantInfo),
                                                                            payloadSize.ToString(NumberFormatInfo.InvariantInfo)));
                        }

                        // Start reading the remaining frame data (note header does not count).
                        byte[] frame = new byte[payloadSize];
                        // Save the ref of the data block
                        workerResult.Buffer = frame;
                        workerResult.End = frame.Length;
                        workerResult.Offset = 0;

                        // Transport.BeginRead below will pickup those changes.
                    }
                    else
                    {
                        workerResult.HeaderDone = false; // Reset for optional object reuse.
                        workerResult.InvokeCallback(workerResult.End);
                        return;
                    }
                }

                // This means we need more data to complete the data block.
//.........这里部分代码省略.........
开发者ID:geoffkizer,项目名称:corefx,代码行数:101,代码来源:StreamFramer.cs

示例5: EndRead

        /*++
            EndRead - Finishes off the Read for the Connection
            EndReadWithoutValidation

            This method completes the async call created from BeginRead,
            it attempts to determine how many bytes were actually read,
            and if any errors occured.

            Input:
                asyncResult - created by BeginRead

            Returns:
                int - size of bytes read, or < 0 on error

        --*/

        public override int EndRead(IAsyncResult asyncResult) {
#if DEBUG
            using (GlobalLog.SetThreadKind(ThreadKinds.User)) {
#endif
            if (Logging.On) Logging.Enter(Logging.Web, this, "EndRead", "");

            //
            // parameter validation
            //
            if (asyncResult==null) {
                throw new ArgumentNullException("asyncResult");
            }

            int bytesTransferred;
            bool zeroLengthRead = false;
            if ((asyncResult.GetType() == typeof(NestedSingleAsyncResult)) || m_Chunked)
            {
                LazyAsyncResult castedAsyncResult = (LazyAsyncResult)asyncResult;
                if (castedAsyncResult.AsyncObject != this)
                {
                    throw new ArgumentException(SR.GetString(SR.net_io_invalidasyncresult), "asyncResult");
                }
                if (castedAsyncResult.EndCalled)
                {
                    throw new InvalidOperationException(SR.GetString(SR.net_io_invalidendcall, "EndRead"));
                }
                castedAsyncResult.EndCalled = true;

                if (ErrorInStream)
                {
                    GlobalLog.LeaveException("ConnectStream::EndRead", m_ErrorException);
                    throw m_ErrorException;
                }

                object result = castedAsyncResult.InternalWaitForCompletion();

                Exception errorException = result as Exception;
                if (errorException != null)
                {
                    IOError(errorException, false);
                    bytesTransferred = -1;
                }
                else
                {
                    // If it's a NestedSingleAsyncResult, we completed it ourselves with our own result.
                    if (result == null)
                    {
                        bytesTransferred = 0;
                    }
                    else if (result == ZeroLengthRead)
                    {
                        bytesTransferred = 0;
                        zeroLengthRead = true;
                    }
                    else
                    {
                        try
                        {
                            bytesTransferred = (int) result;

                            if (m_Chunked && (bytesTransferred == 0))
                            {
                                m_ChunkEofRecvd = true;
                                CallDone();
                            }
                        }
                        catch (InvalidCastException)
                        {
                            bytesTransferred = -1;
                        }
                    }
                }
            }
            else
            {
                // If it's not a NestedSingleAsyncResult, we forwarded directly to the Connection and need to call EndRead.
                try
                {
                    bytesTransferred = m_Connection.EndRead(asyncResult);
                }
                catch (Exception exception)
                {
                    if (NclUtilities.IsFatal(exception)) throw;

//.........这里部分代码省略.........
开发者ID:uQr,项目名称:referencesource,代码行数:101,代码来源:_ConnectStream.cs

示例6: EndRenegotiate

		internal void EndRenegotiate (IAsyncResult result)
		{
			if (result == null)
				throw new ArgumentNullException ("asyncResult");

			LazyAsyncResult lazyResult = result as LazyAsyncResult;
			if (lazyResult == null)
				throw new ArgumentException (SR.GetString (SR.net_io_async_result, result.GetType ().FullName), "asyncResult");

			if (Interlocked.Exchange (ref _NestedAuth, 0) == 0)
				throw new InvalidOperationException (SR.GetString (SR.net_io_invalidendcall, "EndRenegotiate"));

			SecureStream.EndRenegotiate (lazyResult);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:14,代码来源:_SslState.cs

示例7: EndWrite

        internal void EndWrite(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new ArgumentNullException(nameof(asyncResult));
            }

            LazyAsyncResult lazyResult = asyncResult as LazyAsyncResult;
            if (lazyResult == null)
            {
                throw new ArgumentException(SR.Format(SR.net_io_async_result, asyncResult.GetType().FullName), nameof(asyncResult));
            }

            if (Interlocked.Exchange(ref _nestedWrite, 0) == 0)
            {
                throw new InvalidOperationException(SR.Format(SR.net_io_invalidendcall, "EndWrite"));
            }

            // No "artificial" timeouts implemented so far, InnerStream controls timeout.
            lazyResult.InternalWaitForCompletion();

            if (lazyResult.Result is Exception)
            {
                if (lazyResult.Result is IOException)
                {
                    throw (Exception)lazyResult.Result;
                }

                throw new IOException(SR.net_io_write, (Exception)lazyResult.Result);
            }
        }
开发者ID:kkurni,项目名称:corefx,代码行数:31,代码来源:SslStreamInternal.cs

示例8: EndProcessAuthentication

        internal void EndProcessAuthentication(IAsyncResult result)
        {
            if (result == null)
            {
                throw new ArgumentNullException("asyncResult");
            }

            LazyAsyncResult lazyResult = result as LazyAsyncResult;
            if (lazyResult == null)
            {
                throw new ArgumentException(SR.Format(SR.net_io_async_result, result.GetType().FullName), "asyncResult");
            }

            if (Interlocked.Exchange(ref _nestedAuth, 0) == 0)
            {
                throw new InvalidOperationException(SR.Format(SR.net_io_invalidendcall, "EndAuthenticate"));
            }

            InternalEndProcessAuthentication(lazyResult);

            // Connection is completed at this point.
            if (Logging.On)
            {
                Logging.PrintInfo(Logging.Web, SR.Format(SR.net_log_sspi_selected_cipher_suite,
                    "EndProcessAuthentication",
                    SslProtocol,
                    CipherAlgorithm,
                    CipherStrength,
                    HashAlgorithm,
                    HashStrength,
                    KeyExchangeAlgorithm,
                    KeyExchangeStrength));
            }
        }
开发者ID:hanzhu101,项目名称:corefx,代码行数:34,代码来源:_SslState.cs

示例9: ReadCallback

        private void ReadCallback(IAsyncResult transportResult) {
            GlobalLog.Assert(transportResult.AsyncState is InnerAsyncResult, "InnerAsyncResult::ReadCallback|The state expected to be of type InnerAsyncResult, received {0}.", transportResult.GetType().FullName);
            if (transportResult.CompletedSynchronously)
            {
                return;
            }

            InnerAsyncResult userResult = transportResult.AsyncState as InnerAsyncResult;
            try {
                // Complete transport IO, in this callback that is always the head stream
                int count;
                if (!m_HeadEOF) {
                    count = m_HeadStream.EndRead(transportResult);
                    m_HeadLength += count;
                }
                else {
                    count = m_TailStream.EndRead(transportResult);
                }


                //check on EOF condition
                if (!m_HeadEOF && count == 0 && userResult.Count != 0) {
                    //Got a first stream EOF
                    m_HeadEOF = true;
                    m_HeadStream.Close();
                    IAsyncResult ar = m_TailStream.BeginRead(userResult.Buffer, userResult.Offset, userResult.Count, m_ReadCallback, userResult);
                    if (!ar.CompletedSynchronously) {
                        return;
                    }
                    count = m_TailStream.EndRead(ar);
                }
                // just complete user IO
                userResult.Buffer = null;
                userResult.InvokeCallback(count);
            }
            catch (Exception e) {
                //ASYNC: try to swallow even serious exceptions (nothing to loose?)
                if (userResult.InternalPeekCompleted)
                    throw;

                userResult.InvokeCallback(e);
            }
            catch {
                //ASYNC: try to swallow even serious exceptions (nothing to loose?)
                if (userResult.InternalPeekCompleted)
                    throw;

                userResult.InvokeCallback(new Exception(SR.GetString(SR.net_nonClsCompliantException)));
            }
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:50,代码来源:_cachestreams.cs

示例10: EndIssue

        /// <summary>
        /// Ends the async call of Issue request. This would finally return the RequestSecurityTokenResponse.
        /// </summary>
        /// <param name="result">The async result returned from the BeginIssue method.</param>
        /// <returns>The security token response.</returns>
        public virtual RSTR EndIssue(IAsyncResult result)
        {
            if (result == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("result");
            }

            if (!(result is TypedAsyncResult<RSTR>))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ID2012, typeof(TypedAsyncResult<RSTR>), result.GetType())));
            }

            return TypedAsyncResult<RSTR>.End(result);
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:19,代码来源:SecurityTokenService.cs

示例11: HandleAsyncEnd

        virtual internal void HandleAsyncEnd(IAsyncResult ar, bool turnProgressOff)
        {
            if((false == ar.GetType().IsSubclassOf(typeof(AsyncResultBase))) &&
                (false == ar.GetType().Equals(typeof(AsyncResultBase))))
                throw new ArgumentException("asyncResult was not returned by a call to End* method.", "asyncResult");

            AsyncResultBase stateObj = (AsyncResultBase)ar;
            if(stateObj.IsHandled)
                throw new InvalidOperationException("End* method was previously called for the asynchronous operation.");

            if(false == stateObj.IsCompleted)
                stateObj.AsyncWaitHandle.WaitOne();

            stateObj.IsHandled = true;

            if(turnProgressOff)
                SetProgress(false);    

            if(null != stateObj.Exception)
            {
                //dumpActivityException(stateObj);
                throw stateObj.Exception;
            }
        }
开发者ID:dvillaseca,项目名称:RatioMaster.NET,代码行数:24,代码来源:AsyncBase.cs

示例12: VerifyAsyncResult

        static internal void VerifyAsyncResult(IAsyncResult ar, 
            Type arType,
            string metName)
        {
            if(null == ar)
                throw new ArgumentNullException("asyncResult", "The value cannot be null.");

            if(null == metName)
                metName = "End*";

            if(false == ar.GetType().Equals(arType))
                throw new ArgumentException("asyncResult was not returned by a call to the " + 
                    metName + " method.", "asyncResult");

            AsyncResultBase stateObj = (AsyncResultBase)ar;
            if(stateObj.IsHandled)
                throw new InvalidOperationException(metName + " was previously called for the asynchronous operation.");
        }
开发者ID:dvillaseca,项目名称:RatioMaster.NET,代码行数:18,代码来源:AsyncBase.cs

示例13: EndWrite

 internal void EndWrite(IAsyncResult asyncResult)
 {
     if (asyncResult == null)
     {
         throw new ArgumentNullException("asyncResult");
     }
     LazyAsyncResult result = asyncResult as LazyAsyncResult;
     if (result == null)
     {
         throw new ArgumentException(SR.GetString("net_io_async_result", new object[] { asyncResult.GetType().FullName }), "asyncResult");
     }
     if (Interlocked.Exchange(ref this._NestedWrite, 0) == 0)
     {
         throw new InvalidOperationException(SR.GetString("net_io_invalidendcall", new object[] { "EndWrite" }));
     }
     result.InternalWaitForCompletion();
     if (result.Result is Exception)
     {
         if (result.Result is IOException)
         {
             throw ((Exception) result.Result);
         }
         throw new IOException(SR.GetString("net_io_write"), (Exception) result.Result);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:_SslStream.cs

示例14: OnAsync

            private void OnAsync(IAsyncResult r)
            {
                try
                {
                    if (m_isRequest)
                        m_stream = m_owner.m_request.EndGetRequestStream(r);
                    else
                        m_response = m_owner.m_request.EndGetResponse(r);
                }
                catch (Exception ex)
                {
                    if (m_timedout)
                        m_exception = new WebException(string.Format("{0} timed out", m_isRequest ? "GetRequestStream" : "GetResponse"), ex, WebExceptionStatus.Timeout, ex is WebException ? ((WebException)ex).Response : null);
                    else
                    {
                        // Workaround for: https://bugzilla.xamarin.com/show_bug.cgi?id=28287
                        var wex = ex;
                        if (ex is WebException && ((WebException)ex).Response == null)
                        {
                            WebResponse resp = null;

                            try { resp = (WebResponse)r.GetType().GetProperty("Response", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(r); }
                            catch {}

                            if (resp == null)
                                try { resp = (WebResponse)m_owner.m_request.GetType().GetField("webResponse", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(m_owner.m_request); }
                                catch { }

                            if (resp != null)
                                wex = new WebException(ex.Message, ex.InnerException, ((WebException)ex).Status, resp);
                        }

                        m_exception = wex;


                    }
                }
                finally
                {
                    m_event.Set();
                }
            }
开发者ID:AlexFRAN,项目名称:duplicati,代码行数:42,代码来源:AsyncHttpRequest.cs

示例15: EndInvoke

        /// <summary>
        /// Waits for the invocation of a delegate to complete, and returns the result of the delegate. This may only be called once for a given <see cref="IAsyncResult"/> object.
        /// </summary>
        /// <param name="result">The <see cref="IAsyncResult"/> returned from a call to <see cref="BeginInvoke"/>.</param>
        /// <returns>The result of the delegate. May not be <c>null</c>.</returns>
        /// <remarks>
        /// <para>If the delegate raised an exception, then this method will raise a <see cref="System.Reflection.TargetInvocationException"/> with that exception as the <see cref="Exception.InnerException"/> property.</para>
        /// </remarks>
        public object EndInvoke(IAsyncResult result)
        {
            Contract.Assume(result != null);
            Contract.Assume(result.GetType() == typeof(AsyncResult));

            // (This method may be invoked from any thread)
            AsyncResult asyncResult = (AsyncResult)result;
            asyncResult.WaitForAndDispose();
            if (asyncResult.Error != null)
            {
                throw asyncResult.Error;
            }

            return asyncResult.ReturnValue;
        }
开发者ID:caesay,项目名称:CS.Util,代码行数:23,代码来源:SynchronizationContextProxy.cs


注:本文中的IAsyncResult.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。