hi. In a datagridview I have an IP address field. when I click on check status button I make thread for each row in datagridview and then call a remote object on the host on that IP and get some information and set another datagridview field as thath info.
but there is a problem. the info is wrongly set on datagridview. why?
private void button_CheckStatus_Click(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView_VSD.Rows.Count; i++)
{
IPAddress IP;
if (IsValidIP(dataGridView_VSD["VSD_IP", i].Value.ToString(), out IP))
{
Thread t = new Thread(() => CheckVSDStatusThreadFunction(IP, i));
t.Start();
}
}
}
private bool IsValidIP(string t, out IPAddress IP)
{
try
{
IPAddress ip = IPAddress.Parse(t);
IP = ip;
return true;
}
catch
{
IP = null;
return false;
}
}
private void CheckVSDStatusThreadFunction(object IP, object rowIndex)
{
IRemoteUpdate temp = (IRemoteUpdate)Activator.GetObject(typeof(IRemoteUpdate), "tcp://" + ((IPAddress)(IP)).ToString() + ":22000/BRU");
try
{
string s = temp.GetInfo();
SetDataGridViewText(s,"VSD_Info", (int)rowIndex);
}
catch
{
SetDataGridViewText("can not estalish connection to VSD", "VSD_UpdateStatus", (int)rowIndex);
}
}
delegate void delSetDataGridViewText(string text, string columnname,int rowindex);
private void SetDataGridViewText(string text,string columnname, int rowindex)
{
if (dataGridView_VSD.InvokeRequired)
{
delSetDataGridViewText d = new delSetDataGridViewText(SetDataGridViewText);
this.Invoke(d, new object[] { text, columnname, rowindex });
}
else
{
dataGridView_VSD[columnname, rowindex].Value = text;
}
}