J. Scott Elblein
Well-known member
I'm having a problem with some background worker code. I call the runworkerasync, dowork runs through it's code apparently fine, and after End Sub, nothing else in the app happens. The progresschanged event does not fire, even though I explicitly call it, neither does the work complete event.
I set the BGW properties right on the control itself when i added it to the form to True (reports progress and supports cancellation)
Here is how I call the BGW from the form:
I added the loop, because I want to make sure the BGW finishes before the rest of the loop continues, that it's contained in. I set a breakpoint on the Dim strString line, which never breaks either.
Here is the BGW code itself
Any advice mucho appreciated
I set the BGW properties right on the control itself when i added it to the form to True (reports progress and supports cancellation)
Here is how I call the BGW from the form:
VB.NET:
BackgroundWorker1.RunWorkerAsync()
' Adding a pause to be sure we send all requests (not working)
Do Until BackgroundWorker1.IsBusy = False
'Debug.Print("BGW is Busy. looping ...")
Threading.Thread.Sleep(100)
Loop
Dim strString As String
I added the loop, because I want to make sure the BGW finishes before the rest of the loop continues, that it's contained in. I set a breakpoint on the Dim strString line, which never breaks either.
Here is the BGW code itself
VB.NET:
Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
If BackgroundWorker1.CancellationPending = False Then
Dim r As HttpWebResponse
Dim h As HttpWebRequest
Dim noCachePolicy As New System.Net.Cache.HttpRequestCachePolicy(System.Net.Cache.HttpRequestCacheLevel.BypassCache)
Dim Query As String = "http://www.yahoo.com" '& txtstuff.Text
h = CType(WebRequest.Create(Query), HttpWebRequest) 'use create shared method of webrequest class. Cast to HTTPWebRequest
h.KeepAlive = False ' set keepalives
h.Referer = "http://www.yahoo.com"
h.CachePolicy = noCachePolicy
r = CType(h.GetResponse, HttpWebResponse) ' get the response of the request
strResponse = New StreamReader(r.GetResponseStream).ReadToEnd
' ## Add progressbar change here, where the 0 is?
'BackgroundWorker1.ReportProgress(0, strResponse)
End If
End Sub
Any advice mucho appreciated