63 845
Assignments Done
99,2%
Successfully Done
In August 2018

Answer to Question #45639 in Visual Basic for vinay

Question #45639
I have made a proxy checker that imports proxy from a text file by open file dialog.i have employed 20 background workers that check first 20 proxies from array now i want to choose another 20 items automatically. How could I do it and also I wanna know that there can be some situation when there can be odd number of proxies like 103 in that situation how to choose that remaining 3 proxies ?
Expert's answer
Imports System.ComponentModel
Public ClassForm1
'lists of workersand proxies
Dim workers AsList(Of BackgroundWorker) = NewList(Of BackgroundWorker)
Dim proxies AsList(Of String)
 
Private SubForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
  'fill list ofworkers
  workers.Add(BackgroundWorker1)
  workers.Add(BackgroundWorker2)
 
  'here filllist of proxies
 
  'first run:starting all background workers
  For Each worker Inworkers
Ifproxies.Count > 0 Then
worker.RunWorkerAsync(proxies(0))
proxies.RemoveAt(0)
EndIf
  Next
End Sub
 
'this sub would be called each time workercompletes current task
Sub queue()
  Ifproxies.Count > 0 Then 'if there are items left in proxies list
ForEach worker Inworkers 'iterate workers
Ifworker.IsBusy = False Then'if free worker is found, give him the next task
 worker.RunWorkerAsync(proxies(0))
  proxies.RemoveAt(0)
  ExitSub 'end sub, the nex completed task wouldcall it again
EndIf
Next
  Else 'if there are no proxies to process
ForEach worker Inworkers 'iterate workers
Ifworker.IsBusy = True Then'if busy worker is found, exit sub, it woul be calledby next completed task
  ExitSub
EndIf
Next
MsgBox("Allis done") 'the messagebox would be calledonly if all workers are free
  End If
End Sub
 
'binding queue sub for work completed event
Private SubBackgroundWorker1_RunWorkerCompleted(ByValsender As Object,ByVal e AsSystem.ComponentModel.RunWorkerCompletedEventArgs)Handles BackgroundWorker1.RunWorkerCompleted
  queue()
End Sub
 
Private SubBackgroundWorker2_RunWorkerCompleted(ByValsender As Object,ByVal e AsSystem.ComponentModel.RunWorkerCompletedEventArgs)Handles BackgroundWorker2.RunWorkerCompleted
  queue()
End Sub
End Class
 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions