In payment window When client clicks on payment button I want to start a timer. And if the payment processing takes more than let's say 5 second I want to redirect to a page. Below is what I could think of.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SavePayment(PaymentFormMV data)
{
if (Session["startTime"] == null)
{
Session["startTime"] = DateTime.Now;
}
var ticksRemaining = DateTime.Now - (DateTime)Session["startTime"];
int x = int.Parse(ticksRemaining.ToString()); // Format Unhandled exception
if(x == 5)
{
return RedirectToAction("Index", "Home");
}
// Payment Logic Here to 3rd Party API
return View("PaymentConfirmation", returnData);
}
But it's not working as I expect when I calculate ticksRemaining. Do I need some theading or something here. I am new to development please guide me. I just want see the time duration between button click and current time. If it crosses 5 second I want to redirect the user to a new page.