parallel.foreach with custom collection

Posted by SchwartzE on Stack Overflow See other posts from Stack Overflow or by SchwartzE
Published on 2010-05-28T17:24:55Z Indexed on 2010/05/28 17:31 UTC
Read the original article Hit count: 138

Filed under:
|
|

I am extending the System.Net.Mail.MailAddress class to include an ID field, so I created a new custom MailAddress class that inherited from the existing class and a new custom MailAddressCollection class. I then overrode the existing System.Net.Mail.MailMessage.To to use my new collection. I would like to process the recipients in parallel, but I can't get the syntax right. This is the syntax I am using.

Parallel.ForEach(EmailMessage.To, (MailAddress address) =>
{
    emailService.InsertRecipient(emailId, address.DisplayName, address.Address, " ");
});

I get the following errors:

The best overloaded method match for 'System.Threading.Tasks.Parallel.ForEach(System.Collections.Generic.IEnumerable, System.Action)' has some invalid arguments

Argument 1: cannot convert from 'EmailService.MailAddressCollection' to 'System.Collections.Generic.IEnumerable'

What syntax do I need to use custom collections?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .net-4.0