I have the following problem:

I have written little console application that sends emails. It behaves in the following manner:

* when I run this application in debug mode and go through code step by step it sends emails;
* when I run this application in debug mode and do not go through code step by step, last email does not get sent;
* when I build and move application to server and create a task for it, last email does not get sent;
* when I execute application from Windows explorer (double click on .exe file), last email does not get sent;
* when I execute application from command prompt it sends all emails;

What is interesting is that when I put thread.sleep(200) all emails are sent! Note that I am using this code in my ASP applications and all mails are sent always. If mail has attachment, it is always sent, even if it is last in queue (but this is another application that works correctly).

Code that I use (class for mailing):

```
 Public Class Mailer

        ' Methods
        Public Sub SendMail()
            Dim mail As New MailMessage(Me.Sender, Me.To, Me.Subject, Me.Body)
            mail.IsBodyHtml = True
            If Not Me.CC.Trim.Equals("") Then
                mail.CC.Add(Me.CC)
            End If
            If Not Me.BCC.Trim.Equals("") Then
                mail.Bcc.Add(Me.BCC)
            End If
            Dim client As New SmtpClient(Me.MailServer)
            client.Credentials = New NetworkCredential(Me.Username, Me.Password)
            client.Send(mail)
            mail.Dispose()
        End Sub

        ' Properties
        Public Property Attachments As String
            Get
                Return Me._attachments
            End Get
            Set(ByVal value As String)
                Me._attachments = value
            End Set
        End Property

        Public Property BCC As String
            Get
                Return Me._BCC
            End Get
            Set(ByVal value As String)
                Me._BCC = value
            End Set
        End Property

        Public Property Body As String
            Get
                Return Me._body
            End Get
            Set(ByVal value As String)
                Me._body = value
            End Set
        End Property

        Public Property CC As String
            Get
                Return Me._CC
            End Get
            Set(ByVal value As String)
                Me._CC = value
            End Set
        End Property

        Public ReadOnly Property MailSent As Boolean
            Get
                Return Me._mailSent
            End Get
        End Property

        Public Property MailServer As String
            Get
                Return Me._mailServer
            End Get
            Set(ByVal value As String)
                Me._mailServer = value
            End Set
        End Property

        Public Property Password As String
            Get
                Return Me._password
            End Get
            Set(ByVal value As String)
                Me._password = value
            End Set
        End Property

        Public Property Sender As String
            Get
                Return Me._sender
            End Get
            Set(ByVal value As String)
                Me._sender = value
            End Set
        End Property

        Public Property Subject As String
            Get
                Return Me._subject
            End Get
            Set(ByVal value As String)
                Me._subject = value
            End Set
        End Property

        Public Property [To] As String
            Get
                Return Me._recepients
            End Get
            Set(ByVal value As String)
                Me._recepients = value
            End Set
        End Property

        Public Property Username As String
            Get
                Return Me._username
            End Get
            Set(ByVal value As String)
                Me._username = value
            End Set
        End Property

        ' Fields
        Private _attachments As String
        Private _BCC As String
        Private _body As String
        Private _CC As String
        Private _mailSent As Boolean
        Private _mailServer As String
        Private _password As String
        Private _recepients As String
        Private _sender As String
        Private _subject As String
        Private _username As String
    End Class

```

Code that sends emails:

```
Do While rd.Read

    Dim m As New LinksMailer.Mailer

    m.MailServer = ConfigurationSettings.AppSettings.Item("mailServer")
    m.Username = ConfigurationSettings.AppSettings.Item("mailUsername")
    m.Password = ConfigurationSettings.AppSettings.Item("mailPassword")
    m.Sender = ConfigurationSettings.AppSettings.Item("sender")
    m.To = Conversions.ToString(rd.Item("Email"))
    m.CC = ConfigurationSettings.AppSettings.Item("Cc")
    m.BCC = ConfigurationSettings.AppSettings.Item("Bcc")
    m.Subject = "Some subject...."
    m.Body = "Some HTML body..."
    m.SendMail()

    ' when I add this line everything works!!!
    ' Threading.Thread.Sleep(200)
Loop

```

What is happening here???