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


C# Connection.BeginConnect方法代码示例

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


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

示例1: SendRequest

      public void SendRequest(Uri uri, BplMessage request, Action<BplContextNode> onResponse, Action<GeneralFailure> onFailure) {
         if (uri == null) {
            var formatter = BplXmlFormatter.Minimal;
            var info = formatter.Format(request) ? formatter.Output : "(unknown)";
            throw new BplServiceHandlerException("Unspecified URI invoking request: " + info);
         }
         var entry = onResponse != null ? new InboxEntry { Request = request, ResponseHandler = onResponse, FailureHandler = onFailure } : null;

         // connection state is deliberatelly not checked, because the connection can be in BeginConnect-ing state
         // in which there's no problem to add to Outbox/Inbox and call NextAction (which will do nothing, 
         // because _canWrite/_canRead are false, and the sending will be done later, when EndConnect happens). 
         // Besides, this is designed to well-connected clients, so polling socket for no real reason is not a good idea.
         //
         var c = _outConnections.Find(uri);
         if (c == null) {
            c = new Connection();
            c.BeginConnect(uri);
         } else {
            if (c.Outbox.RequestCount >= CommunicationManager.MaxOutgoingRequests) {
               Log.Warn("Outgoing requests queue is full ({0} items)", c.Outbox.RequestCount);
               if (onFailure != null) onFailure(new GeneralFailure(GeneralFailureCode.ServiceUnavailable));
               return;
            }
         }

         c.Outbox.Add(request, null);
         c.Inbox.Add(entry);
         c.NextAction();
      }
开发者ID:borkaborka,项目名称:gmit,代码行数:29,代码来源:CommunicationManager.cs


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