1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

need help c# foreach loop x times and wait??

Discussion in 'C, C++, C#' started by sandrine10, Apr 27, 2015.

  1. sandrine10

    sandrine10 Jr. VIP Jr. VIP

    Joined:
    Apr 14, 2010
    Messages:
    691
    Likes Received:
    70
    Gender:
    Female
    Location:
    WakWak
    Hi guys,

    i have a datatable with 100's rows,i used foreach loop to go over each row in datatable,and wanna wait 10 seconds after 10 loops how can i do that using c# please?
    my code like this:

    datatable dt=new datatable;
    for each(row in rows){
    action
    }
    after 10 rows need to wait and restart with the next rows

    thanks in advance.
     
  2. AutomationSorcerer

    AutomationSorcerer Registered Member

    Joined:
    Apr 25, 2015
    Messages:
    73
    Likes Received:
    66
    Occupation:
    Senior Software Engineer
    Location:
    Ethereal Plane
    Modulus operator is your friend.

    Code:
    int i = 1;
    datatable dt=new datatable;
    
    for each(row in rows){
        if (i % 10 == 0)
            Thread.Sleep(10000);
        action();
        i++;
    }
    
     
    • Thanks Thanks x 1