本文整理汇总了C#中Windows.Networking.Sockets.DatagramSocket.CancelIOAsync方法的典型用法代码示例。如果您正苦于以下问题:C# DatagramSocket.CancelIOAsync方法的具体用法?C# DatagramSocket.CancelIOAsync怎么用?C# DatagramSocket.CancelIOAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Networking.Sockets.DatagramSocket
的用法示例。
在下文中一共展示了DatagramSocket.CancelIOAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
private async void Search(string st, TimeSpan? timeout = null)
{
Log("Search - " + st);
var ssdp_data = new StringBuilder()
.Append("M-SEARCH * HTTP/1.1").Append("\r\n")
.Append("HOST: ").Append(MULTICAST_ADDRESS).Append(":").Append(SSDP_PORT.ToString()).Append("\r\n")
.Append("MAN: ").Append("\"ssdp:discover\"").Append("\r\n")
.Append("MX: ").Append(MX.ToString()).Append("\r\n")
.Append("ST: ").Append(st).Append("\r\n")
.Append("\r\n")
.ToString();
var adapters = TargetNetworkAdapters ?? await GetActiveAdaptersAsync().ConfigureAwait(false);
await Task.WhenAll(adapters.Select(async adapter =>
{
using (var socket = new DatagramSocket())
{
socket.Control.DontFragment = true;
socket.MessageReceived += OnDatagramSocketMessageReceived;
try
{
await socket.BindServiceNameAsync("", adapter);
using (var output = await socket.GetOutputStreamAsync(MULTICAST_HOST, SSDP_PORT.ToString()))
{
using (var writer = new DataWriter(output))
{
writer.WriteString(ssdp_data);
await writer.StoreAsync();
}
}
await Task.Delay(timeout ?? DEFAULT_TIMEOUT).ConfigureAwait(false);
Log("Search Timeout");
await socket.CancelIOAsync();
}
catch (Exception e)
{
Log("Failed to send multicast: " + e.StackTrace);
}
socket.MessageReceived -= OnDatagramSocketMessageReceived;
}
})).ConfigureAwait(false);
Finished?.Invoke(this, new EventArgs());
}