我想从 aspx 页面检索数据。但是,如果填充,则在静态字段中等待数据。
查询:
$.ajax({
url: "Services/JSON/GetMessage.aspx",
type: "GET",
dataType: "json",
success: function (response) { alert(response.Text); },
error: function (x, t, m) {
if (t === "timeout") {
alert("got timeout");
} else {
alert(t);
}
}
})
服务/JSON/GetMessage.aspx
<%@ Page Language="C#" %>
<%
Response.Clear();
Response.ContentType = "text/json";
int tryCount = 0;
while (1 == 1)
{
if (ClsStaticFields.Messages.Count > 0)
{
foreach(string message in ClsStaticFields.Messages) {
Response.Write("{ Text:'" + message + "' }");
}
}
tryCount ++;
if (tryCount > 29) break; // 1 Minute wait and exit
System.Threading.Thread.Sleep(2000); // 2 Second wait
}
Response.End();
%>
我很好奇:
- 这个等待期会影响其他用户吗?
- 这会导致 IIS 或页面上的锁定吗?
- 这种用法对 CPU 有严重影响吗?