Asynchronous Emails


H

headware

I'm trying to send an email from an aspx page using the
SmtpClient.SendAsync() method. However, when I do this I get an error
stating

"Asynchronous operations are not allowed in this context. Page
starting an asynchronous operation has to have the Async attribute set
to true and an asynchronous operation can only be started on a page
prior to PreRenderComplete event"

First off, how does the system know I'm running this operation? And
what is the problem with calling an asynchronous method? I mean guess
you shouldn't expect to know the end result of the method call because
the request could be long gone by the time the async method call
finishes, but what if I don't care?

I can get around this issue in a few ways. I can use the
System.Threading.ThreadPool.QueueUserWorkItem() method to spin off a
new thread which calls SmtpClient.Send() instead of SendAsync(). This
seems to work and for some reason the system doesn't give me the same
warning about using asynchronous operations.

Alternatively, I can set the Async="true" attribute on the aspx @Page
directive and keep the call to SendAsync().

The second option makes me a little nervous because I don't know the
ramifications of making an aspx page use asynchronous processing. MS
documentation on the subject is scant. I've read a few articles on the
web but they are using async processing for different reasons
(typically to free up threads for processing further requests while
the initial request performs some long operation).

Does anyone have any input or experience with this?

Thanks,
Dave
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top