static void Magic() { Dictionary <string, string> ipPairs = new Dictionary <string, string>(); Dictionary <string, bool> oldStatusPingPairs = new Dictionary <string, bool>(); while (true) { if (isFirstRun) { ipPairs = ip.GetIp(); } else { new Thread(new ThreadStart(() => { Thread.Sleep(10000); ip.GetIp(); })).Start(); } foreach (var v in ipPairs) { if (isFirstRun) { oldStatusPingPairs.Add(v.Key, false); } new Thread(new ThreadStart(() => { bool isPing = ping.GetStatus(v.Value); if (oldStatusPingPairs[v.Key] != isPing) { oldStatusPingPairs[v.Key] = isPing; if (isPing) { Thread.Sleep(isFirstRun ? 0 : 5000); } dp.WriteDpeValue(v.Key, "isConnected" + (redu.GetReduNum() == 1 ? "" : $"_{redu.GetReduNum()}"), isPing); } })).Start(); } if (isFirstRun) { Console.WriteLine("Manager is start"); isFirstRun = false; } Thread.Sleep(1000); } }