Execute two async tasks in Parallel in ASP.Net using C#

Last Reply 6 months ago By pandeyism

Posted 6 months ago

I have to read from two folders where are thousands of picture and past them in a folder based in some condition (filering the extension)

        private async Task FillFotoActiveWeb(IEnumerable<string> foto, string destination)
            await Task.Run(() =>
                foreach (var item in foto)

                    if (item.EndsWith("Big.jpg"))

                    var extension = "1Small.jpg";
                    var startIndex = (item.LastIndexOf("\\") + 1);
                    var articolo = item.Substring(startIndex).Replace("1Small.jpg", "");

                    if (Exist(articolo))
                        if (!IsNotActive(articolo))
                            File.Copy(item, destination + articolo + extension);


if i call this method two times in a button click

await FillFotoActiveWeb(fotoWeb, destinationPath);
await FillFotoActiveWeb(fotoStampa, destinationPath);

i see the destination folder is filled by first call and the second call start only when the first end

the question is how can i run symoultaneously this methods?

You are viewing reply posted by: pandeyism 6 months ago.