Backgroundworker questions

A

AAaron123

Is the following OK in Backgroundworker:

Private Sub backgroundWorker1_DoWork(ByVal sender As Object, ByVal e As
DoWorkEventArgs) Handles backgroundWorker1.DoWork

Static index As Integer = 700

Dim filename As String

filename = "Image_" & index.ToString("D4")

'NOTE THE CONTROL WebBrowser1 IS USED

Dim bmp As Drawing.Bitmap = SomeMethod(WebBrowser1.Handle)


bmp.Save("C:\SiteShow\" & filename & ".bmp",
System.Drawing.Imaging.ImageFormat.Bmp)

index += 1

End Sub

or do I need to call something like this.

Private Sub SetText(ByVal [text] As String)
If Me.textBox1.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[text]})
Else
Me.textBox1.Text = [text]
End If
End Sub
although it's not clear to me how to adapt the above!



if I want to do it repeatedly can I in a Timer click event do:
Private Sub Timer1_Tick(...) Handles Timer1.Tick

If Me.backgroundWorker1.IsBusy Then

Exit Sub

Else

Me.backgroundWorker1.RunWorkerAsync()

End If

End Sub



Thanks for any help at all
 
S

Stanimir Stoyanov

I personally prefer the "Is invoke required?" approach. I primarily use it
in (database) projects where tasks have to be threaded and the UI usable all
the time and updated regularly.

Best Regards,
Stanimir Stoyanov | www.stoyanoff.info
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top