Migrating question from old forum:
Error:
SMTP_Singleton_DIAGNOSTIC_LOGGER_NAME
Code:
Public Class Form1
Private _token As Threading.CancellationToken
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim semaphore As New Threading.SemaphoreSlim(5, 5)
For i As Integer = 0 To 20
Task.Factory.StartNew(Sub()
Try
semaphore.Wait(Me._token)
If Me._token.IsCancellationRequested Then Exit Sub
Using client As New SmtpClient
With client
.Host = "smtp.office365.com"
.Username = "bla"
.Password = "bla"
.Port = 587
.SecurityOptions = SecurityOptions.SSLExplicit
End With
Dim mail As Aspose.Email.MailMessage = Aspose.Email.MailMessage.Load(My.Application.Info.DirectoryPath + "\mail.msg")
client.Send(mail)
mail.Dispose()
mail = Nothing
End Using
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
End Sub, Me._token).ContinueWith(Function(x) semaphore.Release())
Next
End Sub
End Class
Sample project:
AsposeThreadProblem.zip (49.7 KB)
Please note taht I have pm to Ikram on the old post, but since we can’t reply in old forum, I’m moving my question to here.