我正在开发一个 Windows 应用程序,在该应用程序中,我需要在运行时从单独的线程中添加清单框中的项目,为此我使用了:
if (chkLBClientsList.InvokeRequired)
chkLBClientsList.Invoke(new MethodInvoker(delegate{chkLBClientsList.Items.Add(GetHostNameByIpAddress(ipAddress));}));
稍后在应用程序中,我需要从清单框中删除项目,为此我使用相同的逻辑:
if (chkLBClientsList.InvokeRequired)
chkLBClientsList.Invoke(new MethodInvoker(delegate { chkLBClientsList.Items.Remove(GetHostNameByIpAddress(GetIpAddress(client))); }));
但它不起作用....因为此语句chkLBClientsList.InvokeRequired
返回 FALSE 值。
请告诉我如何解决这个问题?提前致谢。