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


C# AsyncCallback.?.Invoke方法代码示例

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


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

示例1: BeginConnectProxy

        public void BeginConnectProxy(EndPoint remoteEP, AsyncCallback callback, object state)
        {
            // do nothing

            var r = new FakeAsyncResult(state);
            callback?.Invoke(r);
        }
开发者ID:Ju2ender,项目名称:csharp-e,代码行数:7,代码来源:DirectConnect.cs

示例2: ToBegin

        /// <summary>
        /// 
        /// </summary>
        /// <param name="task"></param>
        /// <param name="callback"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public static IAsyncResult ToBegin(Task task, AsyncCallback callback, object state)
        {
            if (task == null)
                throw new ArgumentNullException(nameof(task));

            var tcs = new TaskCompletionSource<object>(state);
            task.ContinueWith(t =>
            {
                if (task.IsFaulted)
                {
                    if (task.Exception != null)
                        tcs.TrySetException(task.Exception.InnerExceptions);
                }
                else if (task.IsCanceled)
                {
                    tcs.TrySetCanceled();
                }
                else
                {
                    tcs.TrySetResult(null);
                    //tcs.TrySetResult(RpcAction.GetTaskResult(t));
                }

                callback?.Invoke(tcs.Task);
            }/*, TaskScheduler.Default*/);

            return tcs.Task;
        }
开发者ID:chrishaly,项目名称:RpcLite,代码行数:35,代码来源:RpcAsyncHandler.cs

示例3: ToBegin

        /// <summary>
        /// Wraps a <see cref="Task"/> into the Begin method of an APM pattern.
        /// </summary>
        /// <param name="task">The task to wrap.</param>
        /// <param name="callback">The callback method passed into the Begin method of the APM pattern.</param>
        /// <param name="state">The state passed into the Begin method of the APM pattern.</param>
        /// <returns>The asynchronous operation, to be returned by the Begin method of the APM pattern.</returns>
        public static IAsyncResult ToBegin(Task task, AsyncCallback callback, object state)
        {
            var tcs = new TaskCompletionSource(state);
            task.ContinueWith(t => {
                tcs.TryCompleteFromCompletedTask(t);

                callback?.Invoke(tcs.Task);
            }, TaskScheduler.Default);

            return tcs.Task;
        }
开发者ID:jerkka,项目名称:Olan,代码行数:18,代码来源:AsyncFactory.cs

示例4: LazyAsyncResult

 public LazyAsyncResult(SslState sslState, object asyncState, AsyncCallback asyncCallback)
 {
     AsyncState = asyncState;
     asyncCallback?.Invoke(this);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:5,代码来源:FakeLazyAsyncResult.cs

示例5: BeginRead

        /// <summary>
        /// Begins and asynchronous read of the specified stream
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="buffer">The buffer.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="count">The count.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        public static IAsyncResult BeginRead(this Stream stream, byte[] buffer,
            int offset,
            int count,
            AsyncCallback callback,
            object state)
        {
            var result = new AsyncResult(state);

            Task.Run(() =>
            {
                try
                {
                    var data = stream.Read(buffer, offset, count);
                    result.Complete(data);
                    callback?.Invoke(result);
                }
                catch (IOException)
                {
                    // Ignore, possible connection closed
                }
            });

            return result;
        }
开发者ID:unosquare,项目名称:embedio,代码行数:34,代码来源:Extensions.cs

示例6: BeginWrite

 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     Write(buffer, offset, count);
     var tcs = new TaskCompletionSource<object>(state);
     tcs.TrySetResult(null);
     IAsyncResult result = tcs.Task;
     callback?.Invoke(result);
     return result;
 }
开发者ID:damianh,项目名称:OwinHttpMessageHandler,代码行数:9,代码来源:ResponseStream.cs


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