private static void UpdateMenuButtonTag(string ipAddress, string tag){ // Find the RadioButton with the corresponding IP address and update its Tag property var radioButton = Application.Current.MainWindow.FindName(ipAddress) as RadioButton; if (radioButton != null) { radioButton.Tag = tag; }}
private async Task PingAllIps() { foreach (var ipAddress in ipAddresses) { bool isPingSuccessful = await PingIpAddress(ipAddress); // Update the corresponding RadioButton's Tag property UpdateMenuButtonTag(ipAddress, isPingSuccessful ? "Color2" : "Color5"); } }
private readonly List<string> ipAddresses = new() { "192.168.1.1", "8.8.8.8", "8.8.4.4", "10.221.79.32"};private async Task<bool> PingIpAddress(string ipAddress){ using (Ping ping = new Ping()) { try { PingReply reply = await ping.SendPingAsync(ipAddress); return reply.Status == IPStatus.Success; } catch { return false; // Return false if an exception occurs } }}