I want to lock other threads when one thread is running. It is possible in .Net with a lock object. I need do the same in AJAX.
function f_OrnekleriGetir(bKaydet) {
var ddlKlinikId = "<%=ddlKliniklker.ClientID%>";
var iKlinikId = $("#" + ddlKlinikId + " option:selected").val();
var arrOrnekNolar = new Array();
$(".tdOrnekNo").each(function(idx, td) {
var sOrnekNo = $(td).html();
arrOrnekNolar[idx] = sOrnekNo;
});
for (var i = 0; i < arrOrnekNolar.length; i++) {
// i want to wait in here...
f_OrnekGetirKaydet(arrOrnekNolar[i], iKlinikId, bKaydet);
}
}
}
Is it possible?
KR,
Çağın
You can “lock” the main thread with a loop. There’s a few major downsides here, though.
If you want to lock the thread whilst waiting for an Ajax request, you could send the request synchronously. This will have the same downsides as the blocking loop, however.
As MunkiPhD said, you’re probably looking at the issue incorrectly. Callbacks are widely used in JavaScript to avoid blocking the UI thread, it’s almost guaranteed that structuring your code to use a callback function on either a timer or an event will work much better than what you currently have in mind.