0

I have a foreach loop which will go through every string in an array, I want to make a timer which ticks every 100 miliseconds and when it ticks it goes to the other string in the array, so for example:

Ticks 100 miliseconds thepath = Assets/Star/Star_00001.png Ticks 100 miliseconds thepath = Assets/Star/Star_00002.png

So far I have this:

private void Button7_Click(object sender, RoutedEventArgs e)
    {
        string[] images = new string[] { "Star_00001.png", "Star_00002.png", "Star_00003.png", "Star_00004.png", "Star_00005.png", "Star_00006.png", "Star_00007.png";
        string path = "Assets/Star/";

            foreach(string file in images)
            {
              string thepath = Path.Combine(path,file);
              asset.Text = thepath;
            }
    }

How should I approach and do this? (Sorry if you dont understand, i found it hard to explain myself, if you have further questions just comment)

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
Jermain Defo
  • 189
  • 1
  • 1
  • 11

1 Answers1

4

You can simulate a timer using Task.Delay. You'll need to mark your method async so you may await inside it:

private async void Button7_Click(object sender, RoutedEventArgs e)
{
       string[] images = new string[] { "Star_00001.png", "Star_00002.png", "Star_00003.png", "Star_00004.png", "Star_00005.png", "Star_00006.png", "Star_00007.png";

       string path = "Assets/Star/";
       foreach(string file in images)
       {
            string thepath = Path.Combine(path,file);
            asset.Text = thepath;
            await Task.Delay(100);
       }
}
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321