So I have a problem with VB.NET, and specifically the BackgroundWorker1.
I have a function named SystemLoad()
.
When you click a button, it does BackgroundWorker1.RunWorkerAsync()
. No problem here, but the problem is on the DoWork
function.
Inside the DoWork
function, I write SystemLoad()
to call the following function. But, it doesn't work. It does absolutely nothing.
Is there a solution to this? I already tried doing Dim T As New Thread(AddressOf SystemLoad): T.Start()
but it does the same thing, nothing.
Private Sub SystemLoad()
Try
'Log(Prefix & " Resolving target...")
Main.TextBox2.Invoke(Sub() Main.TextBox2.AppendText(Prefix & " Resolving target..."))
Using req As New HttpRequest
req.IgnoreProtocolErrors = True
req.Cookies = New CookieStorage(False)
req.UserAgent = Http.RandomUserAgent
If Main.ComboBox1.SelectedIndex = 0 Then
Dim P As String = Main.Proxies(New Random().Next(Main.ProxiesCount)).ToString
req.Proxy = New HttpProxyClient(P.Split(":")(0), P.Split(":")(1))
'Log(Prefix & " Using proxy " & P)
Main.TextBox2.Invoke(Sub() Main.TextBox2.AppendText(Prefix & " Using proxy " & P))
ElseIf Main.ComboBox1.SelectedIndex = 1 Then
Dim P As String = Main.Proxies(New Random().Next(Main.ProxiesCount)).ToString
req.Proxy = New Socks4ProxyClient(P.Split(":")(0), P.Split(":")(1))
'Log(Prefix & " Using proxy " & P)
Main.TextBox2.Invoke(Sub() Main.TextBox2.AppendText(Prefix & " Using proxy " & P))
ElseIf Main.ComboBox1.SelectedIndex = 2 Then
Dim P As String = Main.Proxies(New Random().Next(Main.ProxiesCount)).ToString
req.Proxy = New Socks5ProxyClient(P.Split(":")(0), P.Split(":")(1))
'Log(Prefix & " Using proxy " & P)
Main.TextBox2.Invoke(Sub() Main.TextBox2.AppendText(Prefix & " Using proxy " & P))
End If
req.ConnectTimeout = Convert.ToInt32(Link.Split("|")(2))
req.KeepAliveTimeout = Convert.ToInt32(Link.Split("|")(2))
req.ReadWriteTimeout = Convert.ToInt32(Link.Split("|")(2))
Dim Respo As String = req.Post(Link.Split("|")(1)).ToString
ResolveTarget(Respo)
End Using
RefreshTimer.Start()
Catch ex As Exception
Main.TextBox2.Invoke(Sub() Main.TextBox2.AppendText(Prefix & " ERROR " & ex.Message))
End Try
End Sub
Here is how I declare the BackgroundWorker1 :
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
BackgroundWorker1.RunWorkerAsync()
End Sub
'SystemLoad() function
Private Sub BackgroundWorker1_DoWork(sender As Object, e As
System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
BeginInvoke(New Action(AddressOf SystemLoad), Nothing)
End Sub
EDIT : I found this code, but the program GUI is crashing ... I put this code in the BackgroundWorker1_DoWork function, not directly in the Form_Load function but it still crashes.
BeginInvoke(New Action(AddressOf SystemLoad), Nothing)