O
O
olegbest12015-12-17 03:06:36
C++ / C#
olegbest1, 2015-12-17 03:06:36

C# SSH keys error when running in multiple threads, what to do?

Hello everyone, I am writing a WinForm app on Sharp, its essence is to make several connections to different ssh. In one thread, the check works fine, but as soon as the second thread starts and more errors begin, as I understand the public keys. I've been looking for solutions for more than a day, but I still don't understand how it works.
Additionally, to work with ssh, I attached the Tamir.SharpSsh extension.
Here is an example of a function that runs in separate threads

private void Potok(Object x)
        {
            string[] tdata = explode(";", (string)x);
            string h = tdata[0];
            string l = tdata[1];
            string p = tdata[2];
 
            ssh = new SshShell(h, l, p);
            try
            {
                ssh.Connect();
                if (ssh.Connected == true)
                {
                    lock (valueLocker)
                    {
                        string goodresult = h + ";" + l + ";" + p + "\r\n";
                        if (File.Exists(outpf))
                        {
                            File.AppendAllText(outpf, goodresult);
                        }
                        else
                        {
                            File.Create(outpf);
                            File.AppendAllText(outpf, goodresult);
                        }
                    }
                }
            }
            catch (Tamir.SharpSsh.jsch.JSchException ex)
            {
                throw ex;
                ssh.Close();
            }
            catch (System.ArgumentException e)
            {
                throw e;
                ssh.Close();
            }
            catch (System.Exception exts)
            {
                throw  exts;
                ssh.Close();
            }            
            pcnt--;
            ssh.Close();
        }

I have already added a bunch of error handlers, but this does not remove the main essence, as I understand it, some kind of session or key manager is needed, but how to attach it and some developments on the network, I think there are a lot of them, but I did not find one for my case , has already started writing on the forums only for the reason that I can not solve the issue on my own. Tell me who can do it, I'm not coding for the first day, but I'm new to this language and network connections

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
olegbest1, 2015-12-17
@olegbest1

Thanks guys from MSDN for solving my question
https://social.msdn.microsoft.com/Forums/en-US/6da...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question