校对被修改枚举可能不会在邮寄时执行问题. [英] colelction was modified enumeration may not execute problem while mailing.

查看:95
本文介绍了校对被修改枚举可能不会在邮寄时执行问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我有一个Windows服务,它会读取定义的规则,然后将电子邮件发送给收件人.在它发送的电子邮件上,在电子邮件的收件人:"部分,收件人电子邮件会重复多次.我需要将它们显示一次.此外,当我调试代码时,我会收到一个异常,例如集合被修改,枚举可能无法执行".但是,我没有在集合中添加或删除某些内容.代码是;

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;

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));
                        }
                    }
                }

推荐答案

删除消息.完全来自foreach.

使用方法的字段(字符串,字符串[]).

在foreach循环之后-执行命令以发送.

验证时-使用经验规则.

rl._ratingtype.ToString().ToUpper().Trim()==小于等于" .ToString().ToUpper().Trim()

问候,
克里斯
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


这篇关于校对被修改枚举可能不会在邮寄时执行问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆