Torna al Thread
// creazione del thread di verifica stato client, elenco completo
private void ThreadVerificaStatoClientElenco()
{
// controlla se la verifica è già in corso
if (_verifica_stato_incorso == 0)
{
System.Threading.Thread thStatusCompleto =
new System.Threading.Thread(
new System.Threading.ThreadStart(VerificaStatoClient));
thStatusCompleto.IsBackground = true;
// disabilita possibilità di lanciare un nuovo thread finchè questo non termina
_verifica_stato_incorso = 1;
btnStatus.Enabled = false;
btnStatusSelected.Enabled = false;
// ferma timer avvisi
timerAggiornaCasi.Enabled = false;
thStatusCompleto.Start();
}
}
// verifica stato dei pc client in elenco
private void VerificaStatoClient()
{
int ip = 0;
string strIP, status = "", nomehost = "";
_client_off = 0;
_client_on = 0;
_client_unknown = 0;
// per ogni client
int tot = dgvElencoClient.RowCount;
for (int i = 0; i < tot; i++)
{
// indirizzo ip del client
strIP = dgvElencoClient.Rows[i].Cells["IP"].Value.ToString();
if (strIP == "")
ip = 0;
else
{
string strLastIP = strIP.Substring(strIP.LastIndexOf('.') + 1);
ip = int.Parse(strLastIP);
}
// sede
int idSede = Convert.ToInt32(dgvElencoClient.Rows[i].Cells["IdSede"].Value); // qui viene generata l'eccezione -----------------
// se sono su DHCP (190..199) o ip = 0,null => guardo nome macchina
if ((ip == 0) || (idSede == 1 && (ip >= 190 && ip <= 199)))
{
// indirizzo IP non valido
// considero il nomehost: se è significativo verifica lo status altimenti no
nomehost = dgvElencoClient.Rows[i].Cells["Client"].Value.ToString();
if (nomehost == "")
status = "-";
else
{
status = FC.VerificaStato(nomehost);
// prova anche con il nome di dominio completo
if (status == "-")
{
nomehost += ".casa.local";
status = FC.VerificaStato(nomehost);
}
}
}
else
status = FC.VerificaStato(strIP);
// parametri da passare tramite delegato per modo thread-safe
object[] parametri = new object[2];
parametri[0] = i;
parametri[1] = status;
this.BeginInvoke(new DSCDelegate(DisplayStatusClient), parametri);
}
// chiamata thread-safe per aggiornamento totali client
this.BeginInvoke(new EventHandler(AggiornaTotali));
}