BackgroundWorker + ProcessBar

  • Thread starter Thread starter noampro8
  • Start date Start date
N

noampro8

Guest
i'm having trouble to combine this 2 together..

i want a progress bar to run when the backgroundWorker starts until the backgrounWorker is finish and in the meantime shows besides the bar also numbers..

for example, i'm sending each time couple of mails, somtimes 3, somtimes 40 so i want it to show the progress:

1/40..17/40..40/40 FINISH..


for now, the progress bar doesnt run accourding to the backgroudWorker Progress..




Private Sub B_Send_Click(sender As Object, e As EventArgs) Handles B_Send.Click


'CHECK HEADER AND BODY MAIL
If Header_TB.Text = "" Then
MsgBox("title is missing")
ElseIf Body_TB.Text = "" Then
MsgBox("content is missing")
Else


'CHECK IF ACCOUNT = GAMIL

Dim GmailAcc As String = My.Settings.MailUser
If GmailAcc <> "" Then
If GmailAcc.Substring(GmailAcc.IndexOf("@") + 1, GmailAcc.IndexOf(".") - GmailAcc.IndexOf("@") - 1) = "gmail" Then



'START SENDING -- go to background

BackgroundWorker1.WorkerReportsProgress = True
backgroundWorker1.RunWorkerAsync()

Else
MsgBox("error..!")
End If
Else

MsgBox("error..")
End If

End If

End Sub


Private Sub BackgroundWorker1_DoWork(ByVal sender as Sstem.Object, ByVal e as System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork


For Each i As String In ListBox1.SelectedItems
' MsgBox(myDataTable.Select("c_name='" & i & "'")(0).Field(Of String)("mail"))
Try

Dim smtp_server As New SmtpClient
Dim e_mail As New MailMessage
smtp_server.UseDefaultCredentials = False
smtp_server.Credentials = New Net.NetworkCredential(My.Settings.MailUser, My.Settings.MailPass)

smtp_server.Port = 587
smtp_server.EnableSsl = True
smtp_server.Host = "smtp.gmail.com"
e_mail = New MailMessage
e_mail.From = New MailAddress(My.Settings.MailUser)
e_mail.To.Add(myDataTable.Select("c_name='" & i & "'")(0).Field(Of String)("mail"))
e_mail.Subject = Header_TB.Text
e_mail.Body = Body_TB.Text
smtp_server.Send(e_mail)

Catch ex As Exception
MsgBox(ex.Message)
End Try


Next
MsgBox("Sent Emails")

End Sub




Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
MessageBox.Show("done!")
End Sub

Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage

End Sub

Continue reading...
 

Similar threads

V
Replies
0
Views
259
Vergassivellaunus
V
V
Replies
0
Views
285
Vergassivellaunus
V
D
Replies
0
Views
121
Developer Dude
D
Back
Top