本文整理汇总了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();
}