I have wrapped the long running logic(longLoop) with setTimeout function, but still UI become unresponsive until long running execcution over. It doesn't allow to click other UI button. Please look at my below example and let me know if any issue you see.
function longLoop () {
var startLogTime, endLogTime;
startLogTime = new Date().getTime();
console.log("loop begin");
for (var i = 0; i <= 500000000; i++) {
var j = 10;
}
endLogTime = new Date().getTime();
console.log("loop execution takes " + (endLogTime - startLogTime) + " milliseconds");
}
$(document).ready(function () {
$("#btnButton").bind("click", function () {
setTimeout(longLoop, 15);
});
$("#anotherButton").bind("click", function () {
console.log("another operation clicked");
});
});
<input type="button" id="btnButton" value="Start Long Operation" />
<input type ="button" id="anotherButton" value= "Another operation" />
Thanks