请查看此代码并找出它不起作用的原因。我没有收到网页中的警报。但是,它下面的console.writeLine正在被执行。
private void PublishLoop()
{
while (Running)
{
Thread.Sleep(5000);
dtMessages = (String)(Cache.Get(key));
if (dtMessages == null)
{
//publish here
dtMessages = LoadMessages();
System.Diagnostics.Debugger.Log(0,null,dtMessages);
Page.ClientScript.RegisterStartupScript(this.GetType(),"ClientScript", "alert('hi');",true);
Console.WriteLine(dtMessages);
}
}
}
编辑:每个响应实际上只能注册一个唯一的键。您正在while循环中运行这行代码,因此它一直在注册相同的密钥。每次调用此函数时,都需要给它一个唯一的键参数。在您的情况下,也许您可以在循环中有一个计数器,并将其附加到密钥字符串中
int i = 0;
while (Running)
{
Thread.Sleep(5000);
dtMessages = (String)(Cache.Get(key));
if (dtMessages == null)
{
//publish here
dtMessages = LoadMessages();
System.Diagnostics.Debugger.Log(0,null,dtMessages);
Page.ClientScript.RegisterStartupScript(this.GetType(),"ClientScript" + i.ToString(), "alert('hi');",true);
Console.WriteLine(dtMessages);
i++;
}
}