Silly DNS.BeginResolve question

  • Thread starter Thread starter ShaneB
  • Start date Start date
S

ShaneB

Hello all!
To test my app's exception handling, I've coded a call to
DNS.BeginResolve() with an intentionally bad host name. When I put the code
in a try/catch block, all works fine and a SocketException is thrown as
expected. However, if I remove the try/catch lines, no exception is thrown.
I've stepped through it with the debugger and as soon as the the methods
hits the line that should throw an exception, it returns immediately as if
one was thrown...but no messagebox is displayed.

I must be missing something very simple here...

TIA,
ShaneB


// CALLING CODE
RequestState myRequestState = new RequestState();
IAsyncResult asyncResult = Dns.BeginResolve("www.whyaintthisworking121.com",
new AsyncCallback(DnsResolveCallback), myRequestState);
// HELPER CLASS
private class RequestState
{
public IPHostEntry Host;

public RequestState()
{
Host = null;
}
}

// CALLBACK
private void DnsResolveCallback(IAsyncResult ar)
{
// Convert the IAsyncResult object to a RequestState object
RequestState tempRequestState = (RequestState)ar.AsyncState;
// End the DNS.Resolve request
// try
//{
tempRequestState.Host = Dns.EndResolve(ar); // this line should
throw a SocketException because I've called BeginResolve earlier with a bad
host name.
//}
// catch (SocketException ex)
//{
// MessageBox.Show("Exception raised...");
//}
}
 
Back
Top