I have a parallel foreach loop running within an event on a asp.net web page. How can I cancel it using cancellation token?This can be a very long operation - and what is bothering me is - it seems to be posting back while the operation is running - so how can I trigger another event to use the cancellation token? Is this possible?
protected void btnSend_Click(object sender, EventArgs e)
{
mailList = tbEmailTo.Text.Split(
new string[] { "," },
StringSplitOptions.RemoveEmptyEntries).ToList();
Parallel.ForEach(emailList, email =>
{
//just sending email
});
}