简体   繁体   English

DataGridView.Invoke引发NullReferenceException

[英]DataGridView.Invoke throws NullReferenceException

i have a problem with DataGridView.Invoke. 我对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. 所以我调用CheckMainTable从ServersTable(由另一个线程使用)获取值到我的MainTable。 and it throws NullReference. 并抛出NullReference。 what am i doing wrong? 我究竟做错了什么?

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 . 如果r.Cells[0]null则可能抛出。

Further, .GetSystemValue would throw if the result from Servers.Find(... were null . 此外,如果.GetSystemValue Servers.Find(...的结果为null.GetSystemValue抛出.GetSystemValue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM