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