How to add a Counter on my Bulk Mail Sender ASP.NET Windows App?
<p>I have built a bulk Email Sender, but it shows a message after sending all the mails. I want to add a counter to the event that will show a message box with a Count that increment the number while sending the Mails. And after sending the mails a message will show the number of total sent mails and unsent mails.</p>

<p>Here is my C# code for the send mail event - </p>

<pre><code>private void btnSendEmail_Click(object sender, EventArgs e)
{
    string subject = txtSubject.Text;
    string message = txtMessage.Text;            
    if (!txtFile.Text.Equals(String.Empty))
    {
        if (System.IO.Directory.GetFiles(txtFile.Text).Length &gt; 0)
        {
            foreach (string file in System.IO.Directory.GetFiles(txtFile.Text))
            {
            }
        }
        else
        {
        }
    }

    var con = "Data Source=Ashiq-pc;Initial Catalog=OfferMails;Integrated Security=True;MultipleActiveResultSets=True";
    List&lt;EmailModel&gt; emailList = new List&lt;EmailModel&gt;();
    using (SqlConnection myConnection = new SqlConnection(con))
    {
        string oString = "Select * from tbl_MailAdd where Flag=@Flag";
        SqlCommand oCmd = new SqlCommand(oString, myConnection);
        oCmd.Parameters.AddWithValue("@Flag", true);     
        myConnection.Open();
        using (SqlDataReader oReader = oCmd.ExecuteReader())
        {
            while (oReader.Read())
            {
                EmailModel emailModel = new EmailModel();
                emailModel.ID = Convert.ToInt16(oReader["ID"]);
                emailModel.EmailAdd = oReader["EmailAdd"].ToString();
                emailModel.Flag = Convert.ToBoolean(oReader["Flag"]);
                emailList.Add(emailModel);                 
            }

            myConnection.Close();
        }               
    }

    //return matchingPerson;
    foreach (EmailModel email in emailList)
    {
        try
        {
            SmtpClient client = new SmtpClient("smtp.gmail.com");
            client.Port = 587;
            client.EnableSsl = true;
            client.Timeout = 100000;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential("my mail", "my pass");
            MailMessage msg = new MailMessage();
            msg.To.Add(email.EmailAdd);
            msg.From = new MailAddress("my from name");
            msg.Subject = subject;
            msg.Body = message;
            if (!txtFile.Text.Equals(String.Empty))
            {
                if (System.IO.Directory.GetFiles(txtFile.Text).Length &gt; 0)
                {
                    foreach (string file in System.IO.Directory.GetFiles(txtFile.Text))
                    {
                        //Add file in ListBox.
                        listAttch.Items.Add(file);
                        //System.Windows.Forms.MessageBox.Show("Files found: " + file, "Message");
                        Attachment data = new Attachment(file);
                        msg.Attachments.Add(data);
                    }
                }
                else
                {
                    //listBox1.Items.Add(String.Format(“No files Found at location : {0}”, textBox1.Text));
                }
            }
            //Attachment data = new Attachment(textBox_Attachment.Text);
            //msg.Attachments.Add(data);
            client.Send(msg);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    //for (int i = 0; i &lt; emailList.Count; i++)
    //{
    //    MessageBox.Show("i++");
    //}

    MessageBox.Show("Successfully Sent Message.");
}
</code></pre>