Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sending Email Asynchronously
Message
From
18/01/2013 11:59:29
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01563134
Message ID:
01563279
Views:
54
>Think my last post was correct. Maybe remove the using when creating the SmtpClient and put 'client.Dispose()' in the delegate callback. i.e in outline:
SmtpClient client = new SmtpClient();
>                    {
>                        client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
>                            try
>                            {
>                                 client.SendCompleted += delegate
>                                {
>                                  client.Dispose();
>                                    lock (numRemainingLock)
>                                    {
>                                        if (--numRemaining == 0)
>                                        {
>                                            waitHandle.Set();
>                                        }
>                                    }
>                                };
>                                client.SendAsync(msg, userState);                 // Send our email.   
>                            }
>                            catch (Exception)
>                            {
>                                msg.Dispose();
>                                // throw;
>                            }
>                        }
>                    }
Superb! Thanks once again Viv. What is interesting is that all the email is now being sent, but the code never hits the SendCompletedCallback.

Oh, it also does not seem to be running asynchronously as I don't get control back in the UI for quite a while.

One of these days I'll understand C# :(
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform