This project is read-only.

Queue (List(Of Task)) of ssh actions on a single device... How?

Jun 20, 2014 at 4:57 PM
Edited Jun 20, 2014 at 4:59 PM

I was scratching my head for hours when all my test code worked fine, but in my production/staging, I could not make the same code create a connection. Nothing really useful from SshClient.Connect(), but it wasn't apparent the issue.

I realized eventually that my app was already talking to the router, and I was trying to also talk to the router, but at the same time. Woops!

So even though the router can have more than one session from the same user, there was no way to create 2 connections from the same application to the same remote device.

This got me thinking (of course, the most complicated way came to mind first)...

-I would write a 'WaitUntilTrue' function at the beginning of anywhere I wanted to talk to the router ( I actually wrote one). If the timeout.. timed out, then I would tell the calling app to wait & try again... But the more I thought about it, the more elegant solution seemed to be one in which I can control which Task gets done first, and whats more, I can see the tasks in the queue (where now there was just no way)...

Seeing as I use Tasks a LOT, I figured I could create a List of them (complete with CancellationTokens), and have the List act as a queue (LIFO), ensuring the router only ever had 1 session at a time coming from my app...

I don't know if you guys & gals have ever had to organize your SshNet connections like this, so I'm just asking what methods you would use with SshNet to accomplish this (am I taking the wrong approach?), and whether there are any niceties built into SshNet that would be useful in doing so.

As always, thanks very much in advance for your responses & discussion! :)