WaitFor and TimeoutException - WeOnlyDo Discussion board

WaitFor and TimeoutException (General questions)

by Scott Blomfield, Tuesday, December 20, 2005, 19:49 (6912 days ago)

I looked in the documentation to find a definite answer to this question because I'm not sure where the problem is stemming from. Will the overload of WaitFor that has a timeout throw a TimeoutException if the timeout expires, or does application flow resume? I am receiving a TimeoutException that appears to be about the time length I specified in Timeout, but I wasn't sure if WaitFor will trigger an exception, since the documentation doesn't specifically say that it will.

I was also having this problem with Receive() (not the timeout overload) so I wasn't sure if it was something else causing it.

Thanks,

Scott

Re: WaitFor and TimeoutException

by Scott Blomfield, Tuesday, December 20, 2005, 19:51 (6912 days ago) @ Scott Blomfield

Sorry, I also meant to say that I set the Timeout on the ssh object to 0, since that will make a difference to how you interpret the problem.

Re: WaitFor and TimeoutException

by wodSupport, Tuesday, December 20, 2005, 20:14 (6912 days ago) @ Scott Blomfield

I'm not sure I understand the problem completely. Yes, Timeout can expire in Waitfor method and that will trigger TimeoutException. What happens after that, hmm. Connection will remain, you can still send/receive, but it's very questionable how much that can help, since I would say you have your connection in unknown state. Since you didn't receive what you expected - what are you going to do now? How will you bail out of it and continue normally? How will you reach command prompt since you don't know what state you're in?

I would say it's better to disconnect and try again. Or, change logic of your application so timeout doesn't expire.

Hope I helped.

Re: WaitFor and TimeoutException

by Scott Blomfield, Wednesday, December 21, 2005, 21:10 (6911 days ago) @ wodSupport

Mostly I wanted to make sure that the TimeoutException was expected as a result of the WaitFor timing out. I had previously only encountered this exception when not sending or receiving any data within the amount of time specified by [SSH].Timeout.

Then once I received that TimeoutException from WaitFor I was unable to do a Receive() on the SSH object to find out what data had been received that did not match the pattern I had placed in WaitFor... It also just triggered another TimeoutException... and since I didn't think Receive (the overload without an int parameter) would throw a TimeoutException it was a bit confusing.

I resolved the issue by setting a breakpoint and checking the returned text before calling WaitFor, then updating my pattern appropriately.

It would be nice if the documentation would list what exceptions each method can potentially raise the same way Microsoft did with the documentation of the Base Class Library.