Alexandera MacQueen
Alexandera MacQueen

Reputation: 99

Run Function base of Time on Background

I do have one function to update my UI: At the moment i call this function more than 8 times in my Action function that will update my UI

   public void CheckStatus()
        {
             this.ovl_stacker1.FillColor =
             OvalShape == MEssage.EMPTY ? Color.Red :
                        OvalShape == Message.WARNING ? Color.Yellow : Color.Green;
            this.OvalShape .Refresh();
}

how can i make this function Auto Run every 5 Sec on my main? ( because i dont want to call the function in other functions many times)

Here is my ActionFunction

       public void Action()
{
//do something....
checkstatus();
//do something.......
checkstatus();
//do something........
checkstatus();
...
...
..
}

Upvotes: 0

Views: 137

Answers (2)

Ely
Ely

Reputation: 3240

I think you would want to use the System.Windows.Forms.Timer class

Upvotes: 0

svick
svick

Reputation: 244757

To call a method every 5 seconds, you could use a timer, but I don't think that's the right solution here. (Although, for a timer to work, you would also need to have the UI thread idle, which it seems you don't.)

Instead, you should call CheckStatus() when you actually change the status, ideally in a setter of the relevant property.

Upvotes: 3

Related Questions