Asynchronous Emails

Discussion in 'ASP .Net' started by headware, Jun 25, 2009.

  1. headware

    headware Guest

    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
    headware, Jun 25, 2009
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shahid Hussain

    How can i Receive Emails from VB.Net

    Shahid Hussain, Nov 17, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    6,496
    Jay B. Harlow [MVP - Outlook]
    Nov 19, 2003
  2. danpres2k
    Replies:
    3
    Views:
    7,470
    danpres2k
    Aug 25, 2003
  3. :crp:
    Replies:
    0
    Views:
    601
    :crp:
    Jan 25, 2005
  4. Savas Ates

    READING EMAILS

    Savas Ates, Jan 27, 2006, in forum: ASP .Net
    Replies:
    13
    Views:
    3,808
    Steven Nagy
    Jan 31, 2006
  5. Bülent Keskin
    Replies:
    1
    Views:
    609
    Guy Soffer
    Aug 10, 2003
Loading...

Share This Page