Multi-Threading proxy checker Object not set to an instance of an object

RamonRobben

I'm trying to make a multi-threaded proxy checker.

I already have a kinda working checker but it gives me this error: Object reference not set to an instance of an object.

I don't know how to solve it and I also don't know why its giving me that error.

Can someone explain me why it is giving me this error and how I should handle it?

Here is my code:

    Private Sub checkProxys(ByVal location As Integer)
    CheckForIllegalCrossThreadCalls = False
    Dim proxy As String

    Do Until location >= ListBox1.Items.Count - 1

        Dim countitems = ListBox1.Items.Count - 1
        ' Console.WriteLine("Location: " & location & "|  Listbox Items: " & ListBox1.Items.Count.ToString & "|  Items - 1: " & countitems.ToString)

        Dim myProxy As WebProxy
        proxy = ListBox1.Items(location).ToString
        ListBox1.Items.RemoveAt(location)

        Try
            myProxy = New WebProxy(proxy)
            Dim r As HttpWebRequest = HttpWebRequest.Create("http://www.google.com")
            r.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36"
            r.Timeout = TrackBar2.Value
            r.Proxy = myProxy
            Dim re As HttpWebResponse = r.GetResponse()
            ListBox2.Items.Add(proxy)
            Label9.Text = "Working proxy's: " & ListBox2.Items.Count.ToString
            Label4.Text = "Proxy's loaded: " & ListBox1.Items.Count
        Catch
            ListBox3.Items.Add(proxy)
            Label10.Text = "Unresponsive proxy's: " & ListBox3.Items.Count.ToString
            Label4.Text = "Proxy's loaded: " & ListBox1.Items.Count
        End Try
    Loop

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    If ListBox1.Items.Count < 1 Then
        MsgBox("Make sure to import a proxy list first.")
    Else
        For x As Integer = 1 To TrackBar1.Value
            Dim checkProxyThread As New Threading.Thread(AddressOf checkProxys)
            checkProxyThread.Start(x)
        Next
    End If

End Sub

error occures at this line: ListBox1.Items.RemoveAt(location)

RamonRobben

So when you access a listbox with alot of threads its kinda unstable when deleting an index because every other item gets an new index wich is the old index - 1

I think this is kinda unstable so as Yacoub Massad mentioned in his comment its better to keep the data in there. And that's exactly what I did.

I found out that I dont need to delete the data. I simply need to go to another index wich isn't edited or used by any other thread. What did I do to solve the problem:

  1. Delete the line: ListBox1.Items.RemoveAt(location)
  2. Just before the loops ends I wrote this line: location = location + TrackBar1.Value

TrackBar1.value is the thread count.

This way the threads are never at the same index or item. This answer is based on what I think that caused the problem.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Python Proxy Scraper / Checker adding multi-threading trouble

From Dev

Object not set to an instance of object

From Dev

Scala Singleton Object with Multi-threading

From Dev

.NET, the SqlConnection object, and multi-threading

From Dev

Object reference not set to an instance of an object

From Dev

Object reference not set to an instance of an object

From Dev

Object reference not set to an instance of an object

From Dev

iTextSharp 7 object reference not set to an instance of an object

From Dev

Navigation Properties, Object not set to an instance of an object

From Dev

nullreferenceexception : object reference not set to an instance of an object

From Dev

ExecuteReader() Object reference not set to an instance of an object error

From Dev

Object reference not set to an instance of an object (Validation for

From Dev

Object not set as an instance of an object in rhino mocks

From Dev

XAML Object reference not set to an instance of an object

From Dev

Object reference not set to an instance of an object error in json

From Dev

Object reference not set to an instance of an object. in sitecore

From Dev

Handle "object reference not set to an instance of an object" error

From Dev

Nuget - Object reference not set to an instance of an object

From Dev

"Object reference not set to an instance of an object" - but nothing is null?

From Dev

Object reference not set to an instance of an object in TempData

From Dev

Getting error: Object reference not set to an instance of an object

From Dev

Object reference not set to an instance of an object MVC 5

From Dev

Object reference not set to an instance of an object work around

From Dev

Debugging error: "Object reference not set to an instance of an object"

From Dev

Object reference isn't set to an instance of an object

From Dev

Excel VBA - Object reference not set to an instance of an object

From Dev

Object reference not set to an instance of an object on remove row

From Dev

C# Object reference not set to an instance of an object

From Dev

Object reference not set to an instance of an object in windows service

Related Related

  1. 1

    Python Proxy Scraper / Checker adding multi-threading trouble

  2. 2

    Object not set to an instance of object

  3. 3

    Scala Singleton Object with Multi-threading

  4. 4

    .NET, the SqlConnection object, and multi-threading

  5. 5

    Object reference not set to an instance of an object

  6. 6

    Object reference not set to an instance of an object

  7. 7

    Object reference not set to an instance of an object

  8. 8

    iTextSharp 7 object reference not set to an instance of an object

  9. 9

    Navigation Properties, Object not set to an instance of an object

  10. 10

    nullreferenceexception : object reference not set to an instance of an object

  11. 11

    ExecuteReader() Object reference not set to an instance of an object error

  12. 12

    Object reference not set to an instance of an object (Validation for

  13. 13

    Object not set as an instance of an object in rhino mocks

  14. 14

    XAML Object reference not set to an instance of an object

  15. 15

    Object reference not set to an instance of an object error in json

  16. 16

    Object reference not set to an instance of an object. in sitecore

  17. 17

    Handle "object reference not set to an instance of an object" error

  18. 18

    Nuget - Object reference not set to an instance of an object

  19. 19

    "Object reference not set to an instance of an object" - but nothing is null?

  20. 20

    Object reference not set to an instance of an object in TempData

  21. 21

    Getting error: Object reference not set to an instance of an object

  22. 22

    Object reference not set to an instance of an object MVC 5

  23. 23

    Object reference not set to an instance of an object work around

  24. 24

    Debugging error: "Object reference not set to an instance of an object"

  25. 25

    Object reference isn't set to an instance of an object

  26. 26

    Excel VBA - Object reference not set to an instance of an object

  27. 27

    Object reference not set to an instance of an object on remove row

  28. 28

    C# Object reference not set to an instance of an object

  29. 29

    Object reference not set to an instance of an object in windows service

HotTag

Archive