• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# AsyncContinuation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中AsyncContinuation的典型用法代码示例。如果您正苦于以下问题:C# AsyncContinuation类的具体用法?C# AsyncContinuation怎么用?C# AsyncContinuation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AsyncContinuation类属于命名空间,在下文中一共展示了AsyncContinuation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: FlushAsync

		protected override void FlushAsync(AsyncContinuation asyncContinuation)
		{
			foreach (var log in logs)
			{
				WrappedTarget.WriteAsyncLogEvent(log);
			}

			logs.Clear();
			base.FlushAsync(asyncContinuation);
		}
开发者ID:304NotModified,项目名称:NLog.ManualFlush,代码行数:10,代码来源:ManualFlushWrapper.cs


示例2: TestEquals

 public void TestEquals()
 {
     var logEvent1 = new LogEventInfo(LogLevel.Debug, "logger1", "message1");
     AsyncContinuation cont1 = new AsyncContinuation(exception => { });
     var async1 = new AsyncLogEventInfo(logEvent1, cont1);
     var async2 = new AsyncLogEventInfo(logEvent1, cont1);
     Assert.True(async1.Equals(async2));
     Assert.True(async1 == async2);
     Assert.False(async1 != async2);
     Assert.Equal(async1.GetHashCode(), async2.GetHashCode());
 }
开发者ID:daniefer,项目名称:NLog,代码行数:11,代码来源:AsyncLogEventInfoTests.cs


示例3: DoSend

        /// <summary>
        /// Actually sends the given text over the specified protocol.
        /// </summary>
        /// <param name="bytes">The bytes to be sent.</param>
        /// <param name="offset">Offset in buffer.</param>
        /// <param name="length">Number of bytes to send.</param>
        /// <param name="asyncContinuation">The async continuation to be invoked after the buffer has been sent.</param>
        /// <remarks>To be overridden in inheriting classes.</remarks>
        protected override void DoSend(byte[] bytes, int offset, int length, AsyncContinuation asyncContinuation)
        {
            var webRequest = WebRequest.Create(new Uri(this.Address));
            webRequest.Method = "POST";

            AsyncCallback onResponse =
                r =>
                {
                    try
                    {
                        using (var response = webRequest.EndGetResponse(r))
                        {
                        }

                        // completed fine
                        asyncContinuation(null);
                    }
                    catch (Exception ex)
                    {
                        if (ex.MustBeRethrown())
                        {
                            throw;
                        }

                        asyncContinuation(ex);
                    }
                };

            AsyncCallback onRequestStream =
                r =>
                {
                    try
                    {
                        using (var stream = webRequest.EndGetRequestStream(r))
                        {
                            stream.Write(bytes, offset, length);
                        }

                        webRequest.BeginGetResponse(onResponse, null);
                    }
                    catch (Exception ex)
                    {
                        if (ex.MustBeRethrown())
                        {
                            throw;
                        }

                        asyncContinuation(ex);
                    }
                };

            webRequest.BeginGetRequestStream(onRequestStream, null);
        }
开发者ID:CharlieBP,项目名称:NLog,代码行数:61,代码来源:HttpNetworkSender.cs


示例4: Flush

        /// <summary>
        /// Flush any pending log messages (in case of asynchronous targets).
        /// </summary>
        /// <param name="asyncContinuation">The asynchronous continuation.</param>
        public void Flush(AsyncContinuation asyncContinuation)
        {
            asyncContinuation = AsyncHelpers.OneTimeOnly(asyncContinuation);

            try
            {
                this.FlushAsync(asyncContinuation);
            }
            catch (Exception ex)
            {
                asyncContinuation(ex);
            }
        }
开发者ID:igalse,项目名称:NLog,代码行数:17,代码来源:Target.cs


示例5: DoClose

 /// <summary>
 ///     Closes the socket.
 /// </summary>
 /// <param name="continuation">The continuation.</param>
 protected override void DoClose(AsyncContinuation continuation)
 {
     lock (this)
     {
         if (asyncOperationInProgress)
         {
             closeContinuation = continuation;
         }
         else
         {
             CloseSocket(continuation);
         }
     }
 }
开发者ID:modulexcite,项目名称:SQLoogle,代码行数:18,代码来源:TcpNetworkSender.cs


示例6: TestNotEquals

        public void TestNotEquals()
        {
            var logEvent1 = new LogEventInfo(LogLevel.Debug, "logger1", "message1");
            AsyncContinuation cont1 = new AsyncContinuation(exception => { });
            AsyncContinuation cont2 = new AsyncContinuation(exception => { InternalLogger.Debug("test"); });
            var async1 = new AsyncLogEventInfo(logEvent1, cont1);
            var async2 = new AsyncLogEventInfo(logEvent1, cont2);
            Assert.False(async1.Equals(async2));
            Assert.False(async1 == async2);
            Assert.True(async1 != async2);

            //2 delegates will return the same hashcode, http://stackoverflow.com/questions/6624151/why-do-2-delegate-instances-return-the-same-hashcode
            //and that isn't really bad, so ignore this
            //   Assert.NotEqual(async1.GetHashCode(), async2.GetHashCode());
        }
开发者ID:daniefer,项目名称:NLog,代码行数:15,代码来源:AsyncLogEventInfoTests.cs


示例7: DoInvoke

        /// <summary>
        ///     Calls the target method. Must be implemented in concrete classes.
        /// </summary>
        /// <param name="parameters">Method call parameters.</param>
        /// <param name="continuation">The continuation.</param>
        protected virtual void DoInvoke(object[] parameters, AsyncContinuation continuation)
        {
            try
            {
                DoInvoke(parameters);
                continuation(null);
            }
            catch (Exception ex)
            {
                if (ex.MustBeRethrown())
                {
                    throw;
                }

                continuation(ex);
            }
        }
开发者ID:modulexcite,项目名称:SQLoogle,代码行数:22,代码来源:MethodCallTargetBase.cs


示例8: PostFilteringTargetWrapperNoFiltersDefined

        public void PostFilteringTargetWrapperNoFiltersDefined()
        {
            var target = new MyTarget();
            var wrapper = new PostFilteringTargetWrapper()
            {
                WrappedTarget = target,
            };

            ((ISupportsInitialize)wrapper).Initialize();
            ((ISupportsInitialize)target).Initialize();

            var events = new LogEventInfo[]
            {
                new LogEventInfo(LogLevel.Debug, "Logger1", "Hello"),
                new LogEventInfo(LogLevel.Info, "Logger1", "Hello"),
                new LogEventInfo(LogLevel.Info, "Logger2", "Hello"),
                new LogEventInfo(LogLevel.Debug, "Logger1", "Hello"),
                new LogEventInfo(LogLevel.Trace, "Logger1", "Hello"),
                new LogEventInfo(LogLevel.Info, "Logger3", "Hello"),
                new LogEventInfo(LogLevel.Error, "Logger1", "Hello"),
            };

            var exceptions = new List<Exception>();

            var continuations = new AsyncContinuation[events.Length];
            for (int i = 0; i < continuations.Length; ++i)
            {
                continuations[i] = exceptions.Add;
            }

            wrapper.WriteLogEvents(events, continuations);

            // make sure all events went through
            Assert.AreEqual(7, target.Events.Count);
            Assert.AreSame(events[0], target.Events[0]);
            Assert.AreSame(events[1], target.Events[1]);
            Assert.AreSame(events[2], target.Events[2]);
            Assert.AreSame(events[3], target.Events[3]);
            Assert.AreSame(events[4], target.Events[4]);
            Assert.AreSame(events[5], target.Events[5]);
            Assert.AreSame(events[6], target.Events[6]);

            Assert.AreEqual(continuations.Length, exceptions.Count, "Some continuations were not invoked.");
        }
开发者ID:igalse,项目名称:NLog,代码行数:44,代码来源:PostFilteringTargetWrapperTests.cs


示例9: RetryingTargetWrapperTest1

        public void RetryingTargetWrapperTest1()
        {
            var target = new MyTarget();
            var wrapper = new RetryingTargetWrapper()
            {
                WrappedTarget = target,
                RetryCount = 10,
                RetryDelayMilliseconds = 1,
            };

            ((ISupportsInitialize)wrapper).Initialize();
            ((ISupportsInitialize)target).Initialize();

            var events = new LogEventInfo[]
            {
                new LogEventInfo(LogLevel.Debug, "Logger1", "Hello"),
                new LogEventInfo(LogLevel.Info, "Logger1", "Hello"),
                new LogEventInfo(LogLevel.Info, "Logger2", "Hello"),
            };

            var exceptions = new List<Exception>();

            var continuations = new AsyncContinuation[events.Length];
            for (int i = 0; i < continuations.Length; ++i)
            {
                continuations[i] = exceptions.Add;
            }

            wrapper.WriteLogEvents(events, continuations);

            // make sure all events went through
            Assert.AreEqual(3, target.Events.Count);
            Assert.AreSame(events[0], target.Events[0]);
            Assert.AreSame(events[1], target.Events[1]);
            Assert.AreSame(events[2], target.Events[2]);

            Assert.AreEqual(continuations.Length, exceptions.Count, "Some continuations were not invoked.");

            // make sure there were no exception
            foreach (var ex in exceptions)
            {
                Assert.IsNull(ex);
            }
        }
开发者ID:igalse,项目名称:NLog,代码行数:44,代码来源:RetryingTargetWrapperTests.cs


示例10: RepeatingTargetWrapperTest1

        public void RepeatingTargetWrapperTest1()
        {
            var target = new MyTarget();
            var wrapper = new RepeatingTargetWrapper()
            {
                WrappedTarget = target,
                RepeatCount = 3,
            };
            ((ISupportsInitialize)wrapper).Initialize();
            ((ISupportsInitialize)target).Initialize();

            var events = new LogEventInfo[]
            {
                new LogEventInfo(LogLevel.Debug, "Logger1", "Hello"),
                new LogEventInfo(LogLevel.Info, "Logger1", "Hello"),
                new LogEventInfo(LogLevel.Info, "Logger2", "Hello"),
            };

            var exceptions = new List<Exception>();

            var continuations = new AsyncContinuation[events.Length];
            for (int i = 0; i < continuations.Length; ++i)
            {
                continuations[i] = exceptions.Add;
            }

            wrapper.WriteLogEvents(events, continuations);

            // make sure all events went through and were replicated 3 times
            Assert.AreEqual(9, target.Events.Count);
            Assert.AreSame(events[0], target.Events[0]);
            Assert.AreSame(events[0], target.Events[1]);
            Assert.AreSame(events[0], target.Events[2]);
            Assert.AreSame(events[1], target.Events[3]);
            Assert.AreSame(events[1], target.Events[4]);
            Assert.AreSame(events[1], target.Events[5]);
            Assert.AreSame(events[2], target.Events[6]);
            Assert.AreSame(events[2], target.Events[7]);
            Assert.AreSame(events[2], target.Events[8]);

            Assert.AreEqual(continuations.Length, exceptions.Count, "Some continuations were not invoked.");
        }
开发者ID:igalse,项目名称:NLog,代码行数:42,代码来源:RepeatingTargetWrapperTests.cs


示例11: DoInvoke

        protected override void DoInvoke(object[] parameters, AsyncContinuation continuation)
        {
            IRestApiClient client = _clientFactory();

            Task<HttpResponseMessage> task;
            switch(HttpMethod.ToLower())
            {
            case "post":
                task = client.PostAsync(Url, GetByteContent(parameters));
                break;

            case "put":
                task = client.PutAsync(Url, GetByteContent(parameters));
                break;

            case "get":
                task = client.GetAsync(new Uri(Url, GetQueryContent(parameters)));
                break;

            default:
                continuation(new Exception("Unsupported HTTP method"));
                return;
            }

            task.ContinueWith(t =>
                              {
                                  try
                                  {
                                      t.Result.EnsureSuccessStatusCode();
                                      continuation(null);
                                  }
                                  catch(Exception ex)
                                  {
                                      continuation(ex);
                                  }
                                  finally
                                  {
                                      client.Dispose();
                                  }
                              });
        }
开发者ID:CodingGorilla,项目名称:NLog-Contrib,代码行数:41,代码来源:RestApiTarget.cs


示例12: DoClose

        /// <summary>
        ///     Closes the socket.
        /// </summary>
        /// <param name="continuation">The continuation.</param>
        protected override void DoClose(AsyncContinuation continuation)
        {
            lock (this)
            {
                try
                {
                    if (socket != null)
                    {
                        socket.Close();
                    }
                }
                catch (Exception exception)
                {
                    if (exception.MustBeRethrown())
                    {
                        throw;
                    }
                }

                socket = null;
            }
        }
开发者ID:modulexcite,项目名称:SQLoogle,代码行数:26,代码来源:UdpNetworkSender.cs


示例13: SingleCallContinuation

 /// <summary>
 /// Initializes a new instance of the <see cref="SingleCallContinuation"/> class.
 /// </summary>
 /// <param name="asyncContinuation">The asynchronous continuation.</param>
 public SingleCallContinuation(AsyncContinuation asyncContinuation)
 {
     this.asyncContinuation = asyncContinuation;
 }
开发者ID:semirs,项目名称:CellAO,代码行数:8,代码来源:SingleCallContinuation.cs


示例14: DoInvoke

        internal void DoInvoke(object[] parameters, AsyncContinuation continuation, HttpWebRequest request, Func<AsyncCallback, IAsyncResult> beginFunc, 
            Func<IAsyncResult, Stream> getStreamFunc)
        {
            Stream postPayload = null;

            switch (this.Protocol)
            {
                case WebServiceProtocol.Soap11:
                    postPayload = this.PrepareSoap11Request(request, parameters);
                    break;

                case WebServiceProtocol.Soap12:
                    postPayload = this.PrepareSoap12Request(request, parameters);
                    break;

                case WebServiceProtocol.HttpGet:
                    this.PrepareGetRequest(request);
                    break;

                case WebServiceProtocol.HttpPost:
                    postPayload = this.PreparePostRequest(request, parameters);
                    break;
            }

            AsyncContinuation sendContinuation =
                ex =>
                {
                    if (ex != null)
                    {
                        continuation(ex);
                        return;
                    }

                    request.BeginGetResponse(
                        r =>
                        {
                            try
                            {
                                using (var response = request.EndGetResponse(r))
                                {
                                }

                                continuation(null);
                            }
                            catch (Exception ex2)
                            {
                                InternalLogger.Error(ex2, "Error when sending to Webservice.");

                                if (ex2.MustBeRethrown())
                                {
                                    throw;
                                }

                                continuation(ex2);
                            }
                        },
                        null);
                };

            if (postPayload != null && postPayload.Length > 0)
            {
                postPayload.Position = 0;
                beginFunc(
                    result =>
                    {
                        try
                        {
                            using (Stream stream = getStreamFunc(result))
                            {
                                WriteStreamAndFixPreamble(postPayload, stream, this.IncludeBOM, this.Encoding);

                                postPayload.Dispose();
                            }

                            sendContinuation(null);
                        }
                        catch (Exception ex)
                        {
                            postPayload.Dispose();
                            InternalLogger.Error(ex, "Error when sending to Webservice.");

                            if (ex.MustBeRethrown())
                            {
                                throw;
                            }

                            continuation(ex);
                        }
                    });
            }
            else
            {
                sendContinuation(null);
            }
        }
开发者ID:MikeFH,项目名称:NLog,代码行数:95,代码来源:WebServiceTarget.cs


示例15: DoSend

 protected override void DoSend(byte[] bytes, int offset, int length, AsyncContinuation asyncContinuation)
 {
     this.log.WriteLine("{0}: send {1} {2}", this.id, offset, length);
     this.MemoryStream.Write(bytes, offset, length);
     if (this.senderFactory.FailCounter > 0)
     {
         this.log.WriteLine("{0}: failed", this.id);
         this.senderFactory.FailCounter--;
         asyncContinuation(new IOException("some IO error has occured"));
     }
     else
     {
         asyncContinuation(null);
     }
 }
开发者ID:rameshr,项目名称:NLog,代码行数:15,代码来源:NetworkTargetTests.cs


示例16: FlushAsync

 protected override void FlushAsync(AsyncContinuation asyncContinuation)
 {
     this.FlushCount++;
     base.FlushAsync(asyncContinuation);
 }
开发者ID:CharlieBP,项目名称:NLog,代码行数:5,代码来源:WrapperTargetBaseTests.cs


示例17: DoClose

 protected override void DoClose(AsyncContinuation continuation)
 {
     this.log.WriteLine("{0}: close", this.id);
     continuation(null);
 }
开发者ID:rameshr,项目名称:NLog,代码行数:5,代码来源:NetworkTargetTests.cs


示例18: FlushAsync

        /// <summary>
        ///     Flushes all pending file operations.
        /// </summary>
        /// <param name="asyncContinuation">The asynchronous continuation.</param>
        /// <remarks>
        ///     The timeout parameter is ignored, because file APIs don't provide
        ///     the needed functionality.
        /// </remarks>
        protected override void FlushAsync(AsyncContinuation asyncContinuation)
        {
            try
            {
                for (var i = 0; i < recentAppenders.Length; ++i)
                {
                    if (recentAppenders[i] == null)
                    {
                        break;
                    }

                    recentAppenders[i].Flush();
                }

                asyncContinuation(null);
            }
            catch (Exception exception)
            {
                if (exception.MustBeRethrown())
                {
                    throw;
                }

                asyncContinuation(exception);
            }
        }
开发者ID:modulexcite,项目名称:SQLoogle,代码行数:34,代码来源:FileTarget.cs


示例19: Flush

 /// <summary>
 /// Flush any pending log messages (in case of asynchronous targets).
 /// </summary>
 /// <param name="asyncContinuation">The asynchronous continuation.</param>
 /// <param name="timeoutMilliseconds">Maximum time to allow for the flush. Any messages after that time will be discarded.</param>
 public static void Flush(AsyncContinuation asyncContinuation, int timeoutMilliseconds)
 {
     factory.Flush(asyncContinuation, timeoutMilliseconds);
 }
开发者ID:bryjamus,项目名称:NLog,代码行数:9,代码来源:LogManager.cs


示例20: Write

 protected override void Write(LogEventInfo logEvent, AsyncContinuation asyncContinuation)
 {
     Assert.IsTrue(this.FlushCount <= this.WriteCount);
     this.WriteCount++;
     ThreadPool.QueueUserWorkItem(
         s =>
             {
                 if (this.ThrowExceptions)
                 {
                     asyncContinuation(new InvalidOperationException("Some problem!"));
                     asyncContinuation(new InvalidOperationException("Some problem!"));
                 }
                 else
                 {
                     asyncContinuation(null);
                     asyncContinuation(null);
                 }
             });
 }
开发者ID:igalse,项目名称:NLog,代码行数:19,代码来源:RoundRobinGroupTargetTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AsyncControllerActionInvoker类代码示例发布时间:2022-05-24
下一篇:
C# AsyncCallback类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap