title: Loop runs too fast?
body: <p>I have a loop (below) that loops N number of times based on user input. the loop, calls a method that creates a random string of text for an insert into a database. I want the loop to call this method before it executes the query, so every insert into the database has a different random string of characters. </p>
  
  <p>What seems to be happening, is that the loop runs too quickly, and the random string is inserted about 50 times because the dynamic string variable doesn't get updated quick enough. However, if I throw in a <code>Thread.Sleep(50)</code>, the code executes perfectly.</p>
  
  <p>I don't like the thread.sleep option because I don't know exactly how long it needs to sleep, and this time will add up if we start running a few hundred thousand transactions.  does anyone have a good solution to ensuring that the method executes completely before it moves on?</p>
  
  <pre><code>for (int i = 0; i &lt; nLoop; i++)
  {
      rnd.RndName();
      query.CommandText = "insert into XXX (col";
      query.ExecuteNonQuery();
  }
  </code></pre>