- Private _Proxies As New List(Of String)
-
Private _Array As New List(Of String)
-
-
Private Sub btnLeech_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Leech_btn.Click
-
Worker.RunWorkerAsync(_Array)
-
End Sub
-
-
'Open a bunch of new threads to download sources of webpages
-
Private Sub Fetch(ByVal sender As System.Object, _
-
ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Worker.DoWork
-
Dim websiteUri As Uri = Nothing
-
Dim Website As String
-
For I = 0 To _Array.ToList.Count - 1
-
Website = _Array(I)
-
Using wc As Net.WebClient = New Net.WebClient
-
AddHandler wc.DownloadStringCompleted, AddressOf SourceDownloaded
-
If Uri.TryCreate(Website, UriKind.Absolute, websiteUri) Then
-
wc.DownloadStringAsync(New Uri(Website))
-
Threading.Thread.Sleep(250)
-
Else
-
If Notify.Checked = True Then
-
TrayIcon.ShowBalloonTip(1, "Invalid website", "There was a invalid site in the list." & Website.ToString, ToolTipIcon.Error)
-
Me.TrashSite_list.Items.Add(Website)
-
Else
-
Me.TrashSite_list.Items.Add(Website)
-
End If
-
End If
-
End Using
-
Next
-
End Sub
-
'Grab the proxies from the webpages
-
Private Sub SourceDownloaded(ByVal sender As Object, ByVal e As Net.DownloadStringCompletedEventArgs)
-
Dim strRegex As String = "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\:[0-9]{1,5}\b"
-
Dim myRegexOptions As RegexOptions = RegexOptions.None
-
Dim myRegex As New Regex(strRegex, myRegexOptions)
-
Dim frm As New Proxies
-
Dim i As Integer
-
My.Settings.Proxies = New StringCollection
-
If e.Error Is Nothing Then
-
For Each myMatch As Match In myRegex.Matches(e.Result)
-
If myMatch.Success Then
-
Try
-
i += i
-
_Proxies.Add(myMatch.ToString)
-
Worker.ReportProgress(i)
-
Catch ex As WebException
-
MessageBox.Show(
-
ex.ToString,
-
ErrorToString,
-
Windows.Forms.MessageBoxButtons.OK)
-
End Try
-
End If
-
Next
-
End If
-
End Sub
-
-
Private Sub Worker_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles Worker.ProgressChanged
-
Proxy_list.Items.AddRange(_Proxies.ToArray)
-
Proxy2_lbl.Text = "Proxies: " & Proxy2_list.Items.Count
-
Proxy_lbl.Text = "Proxies: " & Proxy2_list.Items.Count
-
End Sub
-
This is my code and I want it to update the UI with it but I am unsure how to do so. I am looking for an example with commenting so I can understand it. So far I have posted on a few sites and everyone will tell me what to do or give me an example but nobody will tell me what to do with the example! They expect me to know what the code does, but If I knew what it did, do you really think I'd be asking questions? Anyways, back on topic:
This is what I am trying to accomplish. When I click Leech_btn, it starts my backgroundworker. The background worker downloads the string of a website from the list _Array and moves it over to SourceDownloaded to be filtered. (It removes all the proxies from the website) It then should display the proxies in Proxy_list but this is where I am having trouble. What should I do?
5 4009
So what you're wanting is for someone to just do it for you, and add comments for you? Am I understanding you correctly? If not then please let me know :)
@PsychoCoder
No, I'm looking for someone to spend some actual time responding to my questions and explaining their reasoning and how I should more specifically go about it but I guess I can't expect that here. Especially when this is the first reply and your a mod. Ha.
@Bizzet you're absolutely right, I was having a hard day and took it out on you and for this I apologize. As for your code, did you write that code or was it copied from somewhere (not meant as an insult I promise), just trying to figure out what we can do to help.
Does that code do what you're looking for? If not what does it do versus what you're looking to accomplish?
Well it was, but I have modified it so much that it's not really the same code as the original source anymore. I believe the backgroundworker works as it is suppose to but my UI does get updated. It is suppose to be adding the proxies scraped from the website to my listbox, _Proxylist.
What kind of application are you developing?
If it's WPF, then you should be looking into using the Dispatcher class to update your UI with the stuff you retrieved in your threads.
If it's a win forms application, you'll have to put a sync lock around the code that updates the control and use the ListView.BeginInvoke method to do the updation.
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Richard Bysouth |
last post by:
Hi
In my app I'm using a BackgroundWorker component to execute a long-running
task - updating a progress on my form fine. However, I'd like to provide more
information to that form while the...
|
by: Jakanapes |
last post by:
I'm trying to write my first program using the backgroundworker and am
looking for some example code.
I kow that you can use the UserState member to pass more information
back to the UI for...
|
by: Beorne |
last post by:
Hello, I'm a Java programmer and I'm new to C# (I've read something but
I've no real programming experience). I'm programming a form that
displays some data from an external source (i.e. a com...
|
by: planetthoughtful |
last post by:
Hi All,
I have a Windows Form app that does some work in a BackgroundWorker.
I'd like to append information to a textbox from within the
BackgroundWorker but it keeps telling me that I can't do...
|
by: =?Utf-8?B?SXNobWFlbA==?= |
last post by:
Hi,
I have a form with a progress bar on it and wanted to use the
BackgroundWorker to be able to update the progress. I looked at examples, run
some of them, but in debug, when the code gets to...
|
by: Manikandan |
last post by:
Hi,
I have a form with progress bar.
I'm querying sql server with large number of records(around 1 lakh)
for export
The records are written to a text file
I'm showing the process running by...
|
by: RvGrah |
last post by:
I'm completely new to using background threading, though I have
downloaded and run through several samples and understood how they
worked.
My question is:
I have an app whose primary form...
|
by: Johnny Jörgensen |
last post by:
Hi I have a procudure that takes some time and thus slows down the main
system. I want to put it in a backgroundworker component to run it
asynchroneously. But in the procedure, I want to update a...
|
by: K Viltersten |
last post by:
> bar.PerformStep ();
I noticed that there's a property for the bar stating what time
it should take for the animation to move the fill to the
requested spot. I'm guessing that's the time i...
|
by: Edwin Velez |
last post by:
http://msdn.microsoft.com/en-us/library/806sc8c5.aspx
The URL above gives sample code for use within a Console Application. What
I would like to do is use this code within a Windows Form. That...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |