/// <summary> /// Ends an asynchronous operation to resolve the <see cref="AK.Net.Dns.DnsReply"/> /// instance for a question or query. /// </summary> /// <param name="iar">The asynchronous operation result.</param> /// <returns>The <see cref="AK.Net.Dns.DnsReply"/> containing the answer to /// the query.</returns> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="iar"/> is <see langword="null"/>. /// </exception> /// <exception cref="System.ArgumentException"> /// Thrown when the specified async result does not belong to this operation. /// </exception> /// <exception cref="System.InvalidOperationException"> /// Thrown when /// <see cref="M:AK.Net.Dns.Resolvers.DnsResovler.EndResolve(System.IAsyncResult)"/> /// has already been called on the specified async result. /// </exception> /// <exception cref="AK.Net.Dns.DnsTransportException"> /// Thrown when a transport error occurred during the asynchronous operation. /// </exception> /// <exception cref="AK.Net.Dns.DnsResolutionException"> /// Thrown when an error occurred during the resolution, such as the query /// not being answered. /// </exception> public virtual DnsReply EndResolve(IAsyncResult iar) { Guard.NotNull(iar, "iar"); ResolveAsyncState state = iar as ResolveAsyncState; if (state == null) { throw Guard.InvalidAsyncResult("iar"); } state.OnEndCalled(); return(state.Result); }
/// <summary> /// Begins an asynchronous operation to resolve the <see cref="AK.Net.Dns.DnsReply"/> /// instance for the specified <paramref name="question"/>. /// </summary> /// <param name="question">The <see cref="AK.Net.Dns.DnsQuestion"/> to /// resolve.</param> /// <param name="callback">The method to invoke once the asynchronous operation /// has completed.</param> /// <param name="state">The user-defined state object to associate with the /// asynchronous operation.</param> /// <returns>The asynchronous operation result.</returns> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="question"/> is <see langword="null"/>. /// </exception> public virtual IAsyncResult BeginResolve(DnsQuestion question, AsyncCallback callback, object state) { Guard.NotNull(question, "question"); ResolveAsyncState asyncState = new ResolveAsyncState(callback, state); asyncState.QueueOperation(delegate { try { asyncState.Result = Resolve(question); } catch (DnsException exc) { asyncState.Exception = exc; } finally { asyncState.OnComplete(); } }); return(asyncState); }