点网 mvc5 控制器中的异步函数创建死锁
Async function in dot net mvc5 controller creating deadlock
我将此库用于孟加拉国支付网关。https://github.com/Rahim373/Arts.SslCommerze
.但是控制器中的代码无限期等待iis。如果响应正确地从服务器到达我的机器,我检查了提琴手。它正在达到。但是异步函数没有执行。
我的代码是:
public ActionResult About()
{
string customerName = "Fahim Abrar";
string customerEmail = "fahimabrar13@gmail.com";
string customerPhone = "+8801853912845";
string transactionId = "45c2ffc4d";
string successUrl = "http://fahimabrar.com";
string failUrl = "http://fahimabrar.com";
string cancelUrl = "cancelUrl";
decimal amount = 50;
Customer customer = new Customer(customerName, customerEmail,
customerPhone);
EmiTransaction emiTransaction = new
EmiTransaction(isEmiEnabled: false);
Trasnaction trasnaction = new Trasnaction(amount,
transactionId, successUrl, failUrl,
cancelUrl, emiTransaction, customer);
SslRequest.GetSessionAsync(trasnaction).ConfigureAwait(continueOnCapturedContext: false);
var session = SslRequest.GetSessionAsync(trasnaction).Result;
string s = session.FailedReason;
ViewBag.Message = s;
//"Your application description page.";
return View();
}
这里var session = SslRequest.GetSessionAsync(trasnaction).Result;
此行导致死锁。
.Result
会导致死锁。
制定您的方法 async
并使用 await
例如
public async Task<ActionResult> About()
{
string customerName = "Fahim Abrar";
string customerEmail = "fahimabrar13@gmail.com";
string customerPhone = "+8801853912845";
string transactionId = "45c2ffc4d";
string successUrl = "http://fahimabrar.com";
string failUrl = "http://fahimabrar.com";
string cancelUrl = "cancelUrl";
decimal amount = 50;
Customer customer = new Customer(customerName, customerEmail,
customerPhone);
EmiTransaction emiTransaction = new
EmiTransaction(isEmiEnabled: false);
Trasnaction trasnaction = new Trasnaction(amount,
transactionId, successUrl, failUrl,
cancelUrl, emiTransaction, customer);
var session = await SslRequest.GetSessionAsync(trasnaction);
string s = session.FailedReason;
ViewBag.Message = s;
//"Your application description page.";
return View();
}
我将此库用于孟加拉国支付网关。https://github.com/Rahim373/Arts.SslCommerze .但是控制器中的代码无限期等待iis。如果响应正确地从服务器到达我的机器,我检查了提琴手。它正在达到。但是异步函数没有执行。 我的代码是:
public ActionResult About()
{
string customerName = "Fahim Abrar";
string customerEmail = "fahimabrar13@gmail.com";
string customerPhone = "+8801853912845";
string transactionId = "45c2ffc4d";
string successUrl = "http://fahimabrar.com";
string failUrl = "http://fahimabrar.com";
string cancelUrl = "cancelUrl";
decimal amount = 50;
Customer customer = new Customer(customerName, customerEmail,
customerPhone);
EmiTransaction emiTransaction = new
EmiTransaction(isEmiEnabled: false);
Trasnaction trasnaction = new Trasnaction(amount,
transactionId, successUrl, failUrl,
cancelUrl, emiTransaction, customer);
SslRequest.GetSessionAsync(trasnaction).ConfigureAwait(continueOnCapturedContext: false);
var session = SslRequest.GetSessionAsync(trasnaction).Result;
string s = session.FailedReason;
ViewBag.Message = s;
//"Your application description page.";
return View();
}
这里var session = SslRequest.GetSessionAsync(trasnaction).Result; 此行导致死锁。
.Result
会导致死锁。
制定您的方法 async
并使用 await
例如
public async Task<ActionResult> About()
{
string customerName = "Fahim Abrar";
string customerEmail = "fahimabrar13@gmail.com";
string customerPhone = "+8801853912845";
string transactionId = "45c2ffc4d";
string successUrl = "http://fahimabrar.com";
string failUrl = "http://fahimabrar.com";
string cancelUrl = "cancelUrl";
decimal amount = 50;
Customer customer = new Customer(customerName, customerEmail,
customerPhone);
EmiTransaction emiTransaction = new
EmiTransaction(isEmiEnabled: false);
Trasnaction trasnaction = new Trasnaction(amount,
transactionId, successUrl, failUrl,
cancelUrl, emiTransaction, customer);
var session = await SslRequest.GetSessionAsync(trasnaction);
string s = session.FailedReason;
ViewBag.Message = s;
//"Your application description page.";
return View();
}