VS断点不会停止代码执行

时间:2018-03-07 10:03:42

标签: c# visual-studio breakpoints

此代码非常奇怪的行为。我有一个功能,可以获取发送电子邮件的电子邮件地址和第二个发送邮件的功能。我在第二个函数的开头放置一个断点来查看地址列表,然后我停止代码执行。问题是该程序仍然发送电子邮件。 SMTP客户端代码没有执行(好吧不应该)我会在代码中发表评论来解释更多。

//The calling function 
protected void LogRequest_Click(object sender, EventArgs e)
{
    WriteNewRequest();
   String mysomething = "something";
    SendNewRequestNotification(mysomething , "my subject", "email body");
    ClearForm();

}

private void SendNewRequestNotification(string something, string subject, string message)
{
    List<string> addresslist = new List<string>();
    addresslist.Add(something);
    SendMail(addresslist, subject,message);
}

// I am calling this function
private void SendMail(String address, string subject, string message)
{
    List<string> addresses = new List<string>();
    addresses.Add(address);
    SendMail(addresses,subject,message);
}

private void SendMail(List<String> addresses, string subject, string message)
{
    var toAddress = "";
    toAddress = string.Join(",", addresses.Select(item=>item + "@something.com"));
    //my breakpoint is on the line below. At this point I stop the program. But emails are beign sent. 
    toAddress = "something@something.com"; // this line is just for testing
    var fromAddress = "no.reply@something.com";
    //var subject = "something";
    const string fromPassword = "something";
    string body = message + System.Environment.NewLine + "Date: " + DateTime.Now;
    // smtp settings
    var smtp = new System.Net.Mail.SmtpClient();
    {
       //I put a breakpoint here to test and this never gets a hit but as I said, emails are still being sent. 
        smtp.Host = "smtp.office365.com";
        smtp.Port = 25;
        smtp.EnableSsl = true;
        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        smtp.UseDefaultCredentials = false;
        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
        smtp.Timeout = 600000;
    }
    // Passing values to smtp object
    smtp.Send(fromAddress, toAddress, subject, body);
}

0 个答案:

没有答案
相关问题