I've got a list of Base64 strings that I'm writing to jpeg files on disk by looping through the list. The problem is that not all the files get written. It seems like the operating system doesn't have enough time to write a file to disk before my code moves on to the next item in the list. When I set break point to slow the code, all files get written. I'm using File.WriteAllBytes in C#:
private string WriteJpegs(string photoDate, List<string> photos)
{
...
for (int i=0; i < photos.Count; i++)//loop through list and write jpeg file for each base64
string
{
Random rnd = new Random();
int num = rnd.Next(1, 20000000);
string fileName = photoDate + "_" + Convert.ToString(num) + ".jpg";
string filePath = "PhotoFolder\";
byte[] imageBytes = Convert.FromBase64String(photos[i].ImageData64);
File.WriteAllBytes(filePath + fileName, imageBytes);//if I break here all files get written
}
Do I need to do some kind of asynch operation?
Thanks
Pete
... }