private async Task PingAndUpdateAsync(System.Net.NetworkInformation.Ping ping, string ip) { var reply = await ping.SendPingAsync(ip, timeout); if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) { if (MainWindow.GetMachineNameFromIPAddress(reply.Address.ToString()).Length > 1) { UsersModel x = new UsersModel(); x.pc_name = MainWindow.GetMachineNameFromIPAddress(reply.Address.ToString()); x.ip = reply.Address.ToString(); UM.Add(x); Console.WriteLine(x.ip + " " + x.pc_name); try { SqliteDataAccess.AddUser(x.pc_name, x.ip); } catch (System.Data.SQLite.SQLiteException) { SqliteDataAccess.UpdateUserIp(x.pc_name, x.ip); } } lock (lockObj) { nFound++; ping.Dispose(); } ping.Dispose(); } if (reply.Status != System.Net.NetworkInformation.IPStatus.Success) { ping.Dispose(); } }