private static IAsyncResult HostResolutionBeginHelper(IPAddress address, bool flowContext, bool includeIPv6, AsyncCallback requestCallback, object state)
{
if (address == null)
{
throw new ArgumentNullException(nameof(address));
}
if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
{
throw new ArgumentException(SR.net_invalid_ip_addr, nameof(address));
}
if (NetEventSource.IsEnabled) NetEventSource.Info(null, address);
// Set up the context, possibly flow.
ResolveAsyncResult asyncResult = new ResolveAsyncResult(address, null, includeIPv6, state, requestCallback);
if (flowContext)
{
asyncResult.StartPostingAsyncOp(false);
}
// Start the resolve.
Task.Factory.StartNew(
s => ResolveCallback(s),
asyncResult,
CancellationToken.None,
TaskCreationOptions.DenyChildAttach,
TaskScheduler.Default);
// Finish the flowing, maybe it completed? This does nothing if we didn't initiate the flowing above.
asyncResult.FinishPostingAsyncOp();
return asyncResult;
}