G
Guest
I have read that when using asynchronous IO it is best to keep all your
operations asynchronous. But why if there is nothing left do in the
AsyncCallback method other than to call an IO operation? Example:
//DeliveryHelper is just a class containg an TcpClient and other state
traced variables.
//HelpState.CommStream is a property that returns TcpClient.GetStream()
public void some method()
{
Dns.BeginGetHostAddresses(t[0].Exchange, new
AsyncCallback(EndingMXResolve), HelperState);
}
public void EndingMXResolve(IAsyncResult result)
{
IPAddress[] listedIPs=Dns.EndGetHostAddresses(result);
DeliveryHelper HelperState = result.AsyncState;
HelperState.MessageClient.BeginConnect(listedIPs, 25, new
AsyncCallback(EndingConnect), HelperState);
//nothing left to do...
}
public void EndingConnect(IAsyncReslut result)
{
//end connect;
//begin async read;
}
______________Vs______________________
void some method()
{
Dns.BeginGetHostAddresses(t[0].Exchange, new
AsyncCallback(EndingMXResolve), HelperState);
}
public void EndingMXResolve(IAsyncResult result)
{
IPAddress[] listedIPs=Dns.EndGetHostAddresses(result);
DeliveryHelper HelperState = result.AsyncState;
HelperState.MessageClient.Connect(listedIPs,25);
//once connected do a read;
}
operations asynchronous. But why if there is nothing left do in the
AsyncCallback method other than to call an IO operation? Example:
//DeliveryHelper is just a class containg an TcpClient and other state
traced variables.
//HelpState.CommStream is a property that returns TcpClient.GetStream()
public void some method()
{
Dns.BeginGetHostAddresses(t[0].Exchange, new
AsyncCallback(EndingMXResolve), HelperState);
}
public void EndingMXResolve(IAsyncResult result)
{
IPAddress[] listedIPs=Dns.EndGetHostAddresses(result);
DeliveryHelper HelperState = result.AsyncState;
HelperState.MessageClient.BeginConnect(listedIPs, 25, new
AsyncCallback(EndingConnect), HelperState);
//nothing left to do...
}
public void EndingConnect(IAsyncReslut result)
{
//end connect;
//begin async read;
}
______________Vs______________________
void some method()
{
Dns.BeginGetHostAddresses(t[0].Exchange, new
AsyncCallback(EndingMXResolve), HelperState);
}
public void EndingMXResolve(IAsyncResult result)
{
IPAddress[] listedIPs=Dns.EndGetHostAddresses(result);
DeliveryHelper HelperState = result.AsyncState;
HelperState.MessageClient.Connect(listedIPs,25);
//once connected do a read;
}