for (int i = 0; i < listBox1.Items.Count; i++) { var fil2 = File.ReadAllBytes(@listBox1.Items[i].ToString()); using (FileStream fs = new FileStream("done.exe", FileMode.Append, FileAccess.Write)) { fs.Write(fil2, 0, fil2.Length); } } 

If the cycle goes to 2, then everything is fine, but if the cycle goes up to 3, as it gives an error that it cannot access done.exe because it is busy with another process, can you help solve the problem?

  • 3
    You don’t attach a cart to the donkey, but put the donkey in the cart and ask why it don’t go ?! The for loop needs to be moved inside using (FileStream...) . - Bulson
  • yes, thank you very much - Lolidze
  • @Bulson, why not as an answer? =) - Anton Komyshan
  • one
    @AntonKomyshan is not worth it. - Bulson

0