I have an MVC5 application that processes files. When user clicks run a pop-up box gives the user an option to cancel process, by using CancellationToken. I don't want to invoke this option if user closes the browser. Currently when the user close the browser the CancellationToken gets triggered as well. My goal is to continue running the application if the user close the browser.
C#
CancellationToken ct = Response.ClientDisconnectedToken;
foreach (DirectoryInfo folder in parentFolderInfo.GetDirectories())
{
if (ct.IsCancellationRequested == true)
{
//do something..
break;
}
//some code
}
JS
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.70/jquery.blockUI.js"
type="text/javascript"></script>
<script type="text/javascript">
function UIBlock() {
$.blockUI({ message: "<h4> This may take minutes...\n you may close the browser.</h4><br/><input type='button' value='Cancel Process' id='btncancel' onclick='Abortfun()'/>" });
}
$(document).on('click', '#btncancel', function () {
if (confirm("Are you sure want to stop the process?")) {
ajaxcall.abort();
$.unblockUI();
}
});
</script>
I referred to this post but it didn't help. Thank you.