-1

I need to go through two arraylists (for the ones answering my previous question, I've solved it), one ("dir") has text saved on it which will be used as an Instruction, and the other one ("time") has numbers in it wich will be used for the Interval of a Timer ("Timer.Interval"). What I need to do is to make each position of "Dir" be done continiously until the timer ticks (Timer.Tick), then go to the next position. This is as far as I got:

int i = 0;
for ( i = 0; i > -1; i++)                
{
    Console.WriteLine(cls.dir[i]);
    Console.WriteLine(cls.time[i]);
    if (cls.dir[i] == "one")
    {
         timerSeconds.Interval = Convert.ToInt32(cls.time[i]) * 1000;
         Label1.Text = "Hello StackOverflow";
    }
}

In this case to make it more easy to understand I made and example, what it's supposed to do is to show a different text as a sign in the Label1 as long as the time Arraylist says for each block. I know this is incomplete, how would you end it?

4

1 に答える 1

2

特定のミリ秒数を「待機」したいようです。

もしそうなら、これを行うための最良の方法は「スリープ」を使用することです:

   if (cls.dir[i] == "one")
   {
        int interval = Convert.ToInt32(cls.time[i]) * 1000;
        Label1.Text = "Hello StackOverflow";
        System.Threading.Thread.Sleep(interval);
   }
   Label1.Text = "Time to wake up";
于 2012-11-24T03:57:42.627 に答える