title: Parallel Foreach inside azure function
body: <p>My goal is to watch for new zip blob in a container then unzip a file in az function,push the unzipped files back in different az blob container. I have  deployed my code in a app service plan az function. I used this as my starting base 
  <a href="http://www.frankysnotes.com/2019/02/how-to-unzip-automatically-your-files.html?m=1" rel="nofollow noreferrer">http://www.frankysnotes.com/2019/02/how-to-unzip-automatically-your-files.html?m=1</a></p>
  
  <p>I converted for each below to parallel.foreach with max 4 thread, works great locally on vscode with storage emulator. When i deploy it doesn't run the parrell.foreach part at all. </p>
  
  <pre><code>[FunctionName("Unzipthis")]
  public static async Task Run([BlobTrigger("input-files/{name}", Connection = "cloud5mins_storage")]CloudBlockBlob myBlob, string name, ILogger log)
  {
      log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name}");
  
      string destinationStorage = Environment.GetEnvironmentVariable("destinationStorage");
      string destinationContainer = Environment.GetEnvironmentVariable("destinationContainer");
  
      try{
          if(name.Split('.').Last().ToLower() == "zip"){
  
              CloudStorageAccount storageAccount = CloudStorageAccount.Parse(destinationStorage);
              CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
              CloudBlobContainer container = blobClient.GetContainerReference(destinationContainer);
  
              using(MemoryStream blobMemStream = new MemoryStream()){
  
                  await myBlob.DownloadToStreamAsync(blobMemStream);
  
                  using(ZipArchive archive = new ZipArchive(blobMemStream))
                  {
                      foreach (ZipArchiveEntry entry in archive.Entries)
                      {
                          log.LogInformation($"Now processing {entry.FullName}");
  
                          //Replace all NO digits, letters, or "-" by a "-" Azure storage is specific on valid characters
                          string valideName = Regex.Replace(entry.Name,@"[^a-zA-Z0-9\-]","-").ToLower();
  
                          CloudBlockBlob blockBlob = container.GetBlockBlobReference(valideName);
                          using (var fileStream = entry.Open())
                          {
                              await blockBlob.UploadFromStreamAsync(fileStream);
                          }
                      }
                  }
              }
          }
      }
      catch(Exception ex){
          log.LogInformation($"Error! Something went wrong: {ex.Message}");
  
      }            
  }
  </code></pre>