I understand that I could put a try catch around the SshClient.Disconnect call but it seems like the better place for the try catch would be in the session class where the disconnect message is being sent. If an exception is thrown during a disconnect it could just be ignored.
Comments: ** Comment from web user: Mister_Goodcat **
Hi.
I seem to have the same or at least a related problem, however the consequences are a lot more fatal on my end. Scenario here:
* I connect to a remote server to invoke a command that gracefully shuts down the services there and then turns off the device (it's a NAS). That means that the SSH service is shut down on the server side when I'm still connected.
* On the client, I see two things: first of all the callback of the asynchronously executed command is never invoked, which I think is not expected. I would expect the command to finish and throw an exception when I invoke the EndExecute method in my callback. The only possibility to get notified about the disconnect is to hook the ErrorOccurred event on the client.
* When I try to Disconnect() or Dispose() in that event handler, I seem to get the same race condition, however in my case execution simply hangs and never continues (looks like a dead lock to me, haven't looked at the actual code).
This behavior is fatal on my dev machine when I debug my code in Visual Studio 2012: execution hangs as soon as I invoke Disconnect(), and when I then stop debugging (Shift+F5) __Windows 8 crashes with a BSOD__ telling me the process has still locked pages. I could reproduce this behavior three times in a row after clean reboots.
Running the application outside of Visual Studio does not result in a BSOD, however the thread my code executes on simply dies and never recovers until the process is shut down.
I still think your library is an excellent project and would like to thank you for it; if you could fix that problem, it would be perfect for my use case.
-Peter