BeginConnect: interrupt or set timeout period
-
Hi! I am writing a client/server application that uses sockets as the network interface. When I, in the client code, try to connect to the server by using BeginConnect with the wrong IP-address, my form freezes immediately and remains that way until an exception is thrown. Is there any way to prevent this from happening? Can I control how how long before the exception is thrown? I was using the construct below to solve the timeout issue, but that does not restore the state of my form. I assume the BeginConnect must be interrupted in some way, but I don't know if that can be done? IAsyncResult connResult = this.remoteHost.BeginConnect( remoteEndPoint, null, null ); // wait until the BeginConnect finishes if ( connResult.AsyncWaitHandle.WaitOne(timeOut, false ) ) { } else { // WaitOne timed out }
-
Hi! I am writing a client/server application that uses sockets as the network interface. When I, in the client code, try to connect to the server by using BeginConnect with the wrong IP-address, my form freezes immediately and remains that way until an exception is thrown. Is there any way to prevent this from happening? Can I control how how long before the exception is thrown? I was using the construct below to solve the timeout issue, but that does not restore the state of my form. I assume the BeginConnect must be interrupted in some way, but I don't know if that can be done? IAsyncResult connResult = this.remoteHost.BeginConnect( remoteEndPoint, null, null ); // wait until the BeginConnect finishes if ( connResult.AsyncWaitHandle.WaitOne(timeOut, false ) ) { } else { // WaitOne timed out }
I think the only way is to catch the exception, or verify the IP/hostname beforehand yourself. top secret
Download xacc-ide 0.0.3 now!
See some screenshots