Note that there are some explanatory texts on larger screens.

plurals
  1. POparallel.foreach with custom collection
    text
    copied!<p>I am extending the <code>System.Net.Mail.MailAddress</code> class to include an ID field, so I created a new custom <code>MailAddress</code> class that inherited from the existing class and a new custom <code>MailAddressCollection</code> class. I then overrode the existing <code>System.Net.Mail.MailMessage.To</code> to use my new collection. </p> <p>I would like to process the recipients in parallel, but I can't get the syntax right. This is the syntax I am using.</p> <pre><code>Parallel.ForEach(EmailMessage.To, (MailAddress address) =&gt; { emailService.InsertRecipient(emailId, address.DisplayName, address.Address, " "); }); </code></pre> <p>I get the following errors:</p> <blockquote> <p>The best overloaded method match for 'System.Threading.Tasks.Parallel.ForEach(System.Collections.Generic.IEnumerable, System.Action)' has some invalid arguments </p> <p>Argument 1: cannot convert from 'EmailService.MailAddressCollection' to 'System.Collections.Generic.IEnumerable'</p> </blockquote> <p>What syntax do I need to use custom collections?</p> <p>Here is the EmailService.MailAddress class:</p> <pre><code>public class MailAddress : System.Net.Mail.MailAddress { /// &lt;summary&gt; /// Contains an identifier of the address for use in sending unique email links. /// &lt;/summary&gt; public string ID = ""; public MailAddress(string Address) : base(Address) { } public MailAddress(string Address, string Name): base(Address, Name) { } public MailAddress(string Address, string Name, string Id) : base(Address, Name) { ID = Id; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload