Silly DNS.BeginResolve question

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...");
//}
}
 
S

ShaneB

Disregard....I figured it out. EndResolve is within another thread's
context.

ShaneB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top