We value your feedback.
Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!
Public Function SendEmail(email As String, bodystuff As String) As Task Dim smtp As New SmtpClient("webmail.databarracks.com") Dim from As New MailAddress("firstname.lastname@example.org", "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.
|Help with adding xml file as datasource in MS Report||8||19|
|VB Catch Statement in Event Viewer.||2||20|
|Script to transfer files from web server to sharePoint server||3||33|
|VB .net 2010 Byte array||2||21|
Join the community of 500,000 technology professionals and ask your questions.