开发者

Unable to send mail asynchronously

I'm using a separate class and unique method for sending mail.开发者_JAVA技巧All my web pages, will call the method to send the mail. But, I'm using Client.SendAsync() to send the mail. The following error occurs while sending the mail asynchronously.

"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"

I set Async=true in @page directive, but, as I'm using separate class, so no use of it. Is there any other way to overcome this problem?


Seems you just need to start your async task before PreRenderComplete event; do you mind to post some relevant ASP.NET code?

Also, read this: Running an asynchronous operation triggered by an ASP.NET web page request


This article may be of some help to you:

Fire and Forget Email, Webservices and More in ASP.NET


Setting Async to true is OK if that separated class is declared, instantiated and within the context of the page request.

However you probably need to handle SendCompleted event.

See the sample codes in this MSDN Reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜