Object reference not set to an instance of an object

Shiko 1 Reputation point
2021-05-22T15:49:07.22+00:00

Hi,
I am using Datagridview with BackgroundWorker in vb.net to simultaneously check the network connectivity status of list of IP addresses and it’s working properly if the Ping status of all IPs is Success but I am getting an error states Object reference not set to an instance of an object at the 1st IP with Ping status is Timed Out.

Any idea what could be causing it and how I can overcome it?

Your kind support is highly appreciated.
98802-error2-object-reference-not-set-to-an-instance-of.png

98803-error2-object-reference-not-set-to-an-instance-of.png

Developer technologies | VB
{count} votes

1 answer

Sort by: Most helpful
  1. Sam of Simple Samples 5,571 Reputation points
    2021-05-22T16:41:10.653+00:00

    Is your DoWork accessing the DataGridView directly? You are not supposed to do that. Windows has always not supported accessing a window by any thread that did not create the window. It can work sometimes but Microsoft does not guarantee it will work. You can create a collection (such as a List) for the DataGridView (IP) data and bind the collection to the DataGridView then the DoWork can use the collection. Descriptions of binding a collection to a DataGridView is integrated in the DataGridView Control Overview. I suggest using a BindingSource component as mentioned there. Also see Data Binding - Windows Forms .NET Framework.

    That might also solve the problem in your Looping through Datagridview with BackgroundWorker in vb.net.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.