即使我停止进程,smtp代码也会执行

时间:2014-04-15 16:30:09

标签: c# email debugging

我使用以下代码打开文本文件并向列出的人发送电子邮件并更改主题以包含其ID。我遇到的问题是第一次通过测试我停止了主题行上的调试器。接下来我知道我收到了测试邮件。即使我停止调试器,代码怎么能继续执行?

这是我的代码:

protected void btnTest_Click(object sender, EventArgs e)
{
        string sFilePath = @"C:\email\" + ddlYear.SelectedItem.Value + "-" + ddlMonth.SelectedItem.Value + "_Num.txt";
        using (TextFieldParser parser = new TextFieldParser(sFilePath))
        {
            parser.TextFieldType = FieldType.FixedWidth;
            parser.SetFieldWidths(4, -1);
            int iRowCnt = 1;

            while (!parser.EndOfData)
            {
                string[] sCurrRow = parser.ReadFields();

                try
                {
                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("test@test.com", sCurrRow[1].ToString());
                    message.Subject = txtSubject.Text + " - ID #" + sCurrRow[0].ToString() ;
                    message.IsBodyHtml = Convert.ToBoolean(ddlFormat.SelectedValue);
                    message.Body = txtMsg.Text;
                    System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
                    mailClient.Host = "testSMTP.test.com";
                    mailClient.Credentials = new System.Net.NetworkCredential("TestSMTP", "TESTING");  //Username and password changes
                    mailClient.Send(message);

                    this.InsEmailDB(iRowCnt, iRowCnt, sCurrRow[1].ToString());
                    iRowCnt++;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }                    
            }
        }
    }

2 个答案:

答案 0 :(得分:4)

停止调试器并不会终止程序,它只是停止"观看"它 - 程序仍将运行完毕。

答案 1 :(得分:1)

正如其名称所暗示的那样,调试是免费应用程序。它只显示它是如何执行的。停止调试并不意味着停止应用程序。我认为接收测试邮件不是一个大问题。

相关问题