Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I have a windows service it reads the defined rules and after it sends emails to the recipients. on the emails that it send, on the "To:" part of the email the recipients emails are repeated several times. I needed them to be shown once.Also When I debug the code I receive an exception such as "collection was modified enumeration may not execute".But I am not adding or deleting something from the collection. The code is;
C#
foreach (Rules rl in global_rules)
                {
                    if (rl._ratingtype == "Equal to")
                    {
                        if (Convert.ToInt32(rating) == Convert.ToInt32(rl._rating))
                        {
                            message.To.Add(new System.Net.Mail.MailAddress(rl._mailto));
                        }
                    }
                    else if (rl._ratingtype == "Greater than and equal to")
                    {
                        if (Convert.ToInt32(rating) >= Convert.ToInt32(rl._rating))
                        {
                            message.To.Add(new System.Net.Mail.MailAddress(rl._mailto));
                        }
                    }
                    else if (rl._ratingtype == "Less than and equal to")
                    {
                        if (Convert.ToInt32(rating) <= Convert.ToInt32(rl._rating))
                        {
                            message.To.Add(new System.Net.Mail.MailAddress(rl._mailto));
                        }
                    }
                }
Posted

1 solution

remove the message.To criteria entirely from the foreach.

Use fields to the method (strings , strings[]).

After the foreach loop - execute the command to send.

When validating - rule of experience use something like.

rl._ratingtype.ToString().ToUpper().Trim() == "Less than and equal to".ToString().ToUpper().Trim()

Regards,
Chris
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900