Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. public bool connect(string ip, int port)
  2. {
  3. TcpClient tcpClient = new TcpClient();
  4.  
  5. try
  6. {
  7. tcpClient.Connect(ip, port);
  8. return true;
  9. }
  10. catch
  11. {
  12. return false;
  13. }
  14. finally
  15. {
  16. tcpClient.Close();
  17. }
  18. }
  19.  
  20. private void Form1_Shown(object sender, EventArgs e)
  21. {
  22. List<string> listPath1 = new List<string>();
  23. List<string> listPath2 = new List<string>();
  24.  
  25. GetAllPaths(treeView1.Nodes[0].Nodes[0], listPath1);
  26. GetAllPaths(treeView1.Nodes[0].Nodes[1], listPath2);
  27.  
  28. listPath1.RemoveAt(0);
  29. listPath2.RemoveAt(0);
  30.  
  31. string[] tmp1 = listPath1.ToArray();
  32. string[] tmp2 = listPath2.ToArray();
  33.  
  34. List<Thread> ThrArr = new List<Thread>();
  35. string[] tmp;
  36.  
  37. for (int i = 0; i < tmp1.Length; i++) {
  38. tmp = tmp1[i].Split(' ');
  39. int temp = i;
  40. Thread devthread = new Thread(() => connect(tmp[1], Convert.ToInt32(tmp[4])));
  41.  
  42. devthread.Name = "thr" + i.ToString();
  43. ThrArr.Add(devthread);
  44. //devthread.Start();
  45. //Thread.Sleep(10);
  46. }
  47.  
  48. foreach (Thread thread in ThrArr)
  49. {
  50. thread.Start();
  51. treeView1.Nodes.Add("Potok" + thread.Name);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement