To invoke a method asynchronously by using BeginInvoke and save the result in Session state

我是研究僧i 提交于 2019-12-07 08:20:34

You cannot reliably execute work across HTTP requests because the ASP.NET worker process might be aborted at an arbitrary moment. The payment might have been executed by the provider but your website might think it hasn't (and the payment is lost). I certainly wouldn't want to enter my credit card data into such a system.

A better way to do this is to run the payment on an AJAX request and make the authorization code execute synchronously.

Instead of creating begin invoke and using delegates you can create a method with async keyword and returning the Task.

In your original method you can call the async method as

 Task<int> authorizationValue = await yourAsyncMethodCall(creditcardNumber, expirydate, amount)

  session["authorisation"] = authorizationValue;

Let me know if you need more specific example (my VS.net is broken so i had to type in here :()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!