animekun
animekun

Reputation: 1869

DataGridView.Invoke throws NullReferenceException

i have a problem with DataGridView.Invoke.

delegate void CheckMainTableCallback();
static void CheckMainTable()
{
    if (Program.MonitorApp.ServersTable.InvokeRequired)
    {
        CheckMainTableCallback Safe = new CheckMainTableCallback(CheckMainTable);
        MonitorApp.ServersTable.Invoke(Safe);
    }
    else
    {
        foreach (DataGridViewRow r in MonitorApp.MainTable.Rows)
        {
            **r.Cells["Load"].Value = 
                (Servers.Find(
                    p => p.NAME == r.Cells[0].ToString()
                )
                .GetSystemValue("% Proccess Usage"));** // exception here
        }
    }
}

so i call CheckMainTable to get values from ServersTable ( using by another thread ) to my MainTable. and it throws NullReference. what am i doing wrong?

Upvotes: 0

Views: 101

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67918

So tracking down an exception like this is a piece-by-piece process. Consider the fact that this line of code:

r.Cells[0].ToString()

could throw if r.Cells[0] is null.

Further, .GetSystemValue would throw if the result from Servers.Find(... were null.

Upvotes: 1

Related Questions