Home Ask Login Register

Developers Planet

Your answer is one click away!

Victor February 2016

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;

        bolos = (List<string>)ViewState["bolos"];

    int index = ViewState["index"] != null ? (int)ViewState["index"] : 0;

    if (bolos.Count > 0)
        imgBolo.ImageUrl = bolos[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. However, I've noticed that some Thread.Timer functions don't allow non-static functions to be used.

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.

So I was wondering which would be the most accurate way to refresh an image on the page every 10 seconds.


Maheswari February 2016

You can refresh the page using the html content using Untitled Page

<meta http-equiv="refresh" content="20"  />

Post Status

Asked in February 2016
Viewed 1,652 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life