M
Mark Smith
Hi ,
Is it possible in .Net to define a async timer callback. What I am
wanting to do is declare a time-out condition that gets executed
should the something timeout.
The reason I want to do this is to handle host being down that I am
trying to connect to using TCPIP. Then after a timeout automatically
try another host and just continue trying hosts until someone accepts
a connection, varying my timeout as I loop.
Function1 (string hostname)
{
Socket sock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
IPEndPoint iep = new IPEndPoint(IPAddress.Parse(hostname, 9999);
IAsyncResult ar = sock.BeginConnect(iep, new
AsyncCallback(ConnectedMethod), sock);
Call another ASYNC routine (TryAnotherHost) that defines timer event
callback which if not cancelled executes within 15 seconds.
}
void ConnectedMethod(IAsyncResult iar)
{
Socket socket = (Socket)iar.AsyncState;
socket.EndConnect(iar);
cancel the timer???
<do all my normal stuff>
}
void TryAnotherHost (IAsyncResult iar)
{
Socket socket = (Socket)iar.AsyncState;
socket.EndConnect(iar);
socket.Close();
function1 ("another");
}
Is this possible and what routines should I review to achieve this.
Thanks
Mark
Is it possible in .Net to define a async timer callback. What I am
wanting to do is declare a time-out condition that gets executed
should the something timeout.
The reason I want to do this is to handle host being down that I am
trying to connect to using TCPIP. Then after a timeout automatically
try another host and just continue trying hosts until someone accepts
a connection, varying my timeout as I loop.
Function1 (string hostname)
{
Socket sock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
IPEndPoint iep = new IPEndPoint(IPAddress.Parse(hostname, 9999);
IAsyncResult ar = sock.BeginConnect(iep, new
AsyncCallback(ConnectedMethod), sock);
Call another ASYNC routine (TryAnotherHost) that defines timer event
callback which if not cancelled executes within 15 seconds.
}
void ConnectedMethod(IAsyncResult iar)
{
Socket socket = (Socket)iar.AsyncState;
socket.EndConnect(iar);
cancel the timer???
<do all my normal stuff>
}
void TryAnotherHost (IAsyncResult iar)
{
Socket socket = (Socket)iar.AsyncState;
socket.EndConnect(iar);
socket.Close();
function1 ("another");
}
Is this possible and what routines should I review to achieve this.
Thanks
Mark