Bouquet of small notes:
If you use some kind of .NET API that internally uses ThreadPool, then you cannot wait forever, since the OS owns threads from ThreadPool, these threads are intended to be used "briefly" and then returned back to the OS, that is, the most reliable behavior. Of course, the OS can grow the thread pool as needed if you finish them due to your lengthy processing, but the best design would be to avoid this behavior.
If you work in XP, you may also need to avoid ThreadPool (OS level and therefore .NET), as it was fixed / resigned in Vista and later, the XP version is considered less reliable.
If you use ThreadPool, you end up putting asynchronous work in it, since it is already waiting for work.
Writing your own ThreadManager is pretty easy to do, you can find many examples on this, but as always, these kinds of things should be kept as simple as possible.
For your third point, it is better to restore the SFTP connection than to kill the entire stream. If you kill a thread (if your ThreadManager can handle this, never kill threads from OS ThreadPool, of course), than first you need to return the raw task back to some place, it feels like too much work.
source share