[英]How to use Threading.Timer for a loop on a public non-static method on ASP.NET C#?
I have the following method: 我有以下方法:
//BOLO stands for Be On The Lookout
public void LoadBolos()
{
List<string> bolos;
//If not loaded before
if (ViewState["bolos"] == null)
{
List<string> bolos = GetBolos();
ViewState["bolos"] = bolos;
ViewState["index"] = 0;
}
else
{
bolos = (List<string>)ViewState["bolos"];
}
int index = ViewState["index"] != null ? (int)ViewState["index"] : 0;
if (bolos.Count > 0)
{
imgBolo.ImageUrl = bolos[index];
index++;
index = index >= bolos.Count ? 0 : index;
}
ViewState["index"] = index;
}
I need to loop this method every 10 seconds, so I can refresh an image on the aspx page. 我需要每10秒钟循环一次此方法,以便可以刷新aspx页面上的图像。 However, I've noticed that some Thread.Timer functions don't allow non-static functions to be used.
但是,我注意到某些Thread.Timer函数不允许使用非静态函数。
If I convert this method to static, I can no longer access private variables that load on page load, nor can I use the Viewstate nor access the image. 如果将此方法转换为静态方法,则将无法再访问页面加载时加载的私有变量,也无法使用Viewstate或访问图像。
So I was wondering which would be the most accurate way to refresh an image on the page every 10 seconds. 因此,我想知道哪种方法是每10秒刷新一次页面上图像的最准确方法。
您可以使用无标题页面使用html内容刷新页面
<meta http-equiv="refresh" content="20" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.