Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.
Public Function SendEmail(email As String, bodystuff As String) As Task Dim smtp As New SmtpClient("webmail.databarracks.com") Dim from As New MailAddress("email@example.com", "Info", System.Text.Encoding.UTF8) Dim [to] As New MailAddress(email) Dim message As New MailMessage(from, [to]) message.Body = "The message I want to send is to this <b>contact: " & vbCrLf & bodystuff & "</b>" message.IsBodyHtml = True message.BodyEncoding = System.Text.Encoding.UTF8 message.Subject = "The subject of the email" message.SubjectEncoding = System.Text.Encoding.UTF8 ' Set the method that is called back when the send operation ends. 'AddHandler smtp.SendCompleted, AddressOf smtpClient_SendCompleted Return smtp.SendMailAsync(message) End Function Public Sub StartEmailRun() Try Dim sWatch As New System.Diagnostics.Stopwatch() sWatch.Start() Dim po As New ParallelOptions() 'Create a cancellation token so you can cancel the task. _cancelToken = New CancellationTokenSource() po.CancellationToken = _cancelToken.Token 'Manage the MaxDegreeOfParallelism instead of .NET Managing this. We dont need 500 threads spawning for this. po.MaxDegreeOfParallelism = System.Environment.ProcessorCount * 2 Dim v As Long = 0 Parallel.ForEach(contacts.Cast(Of Object), po, Function(row) Return SendEmail(row.Email.ToString, row.Name.ToString) End Function) 'Here I would like to update my property to True when the above loop is complete?? MyProperty = True sWatch.Stop() Timing = sWatch.ElapsedMilliseconds Catch ex As Exception MsgBox(ex.ToString) End Try End Sub
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.