Problem i'm trying to solve:
For each directory, it exists some files, and I want to upload this to Azure.
So I want to do this: Task1 - uploading files in directory 1 to azure Task 2 - uploading files in directory 2 to azure
I want to do this concurrently.
I have the following code:
private async Task ProcessMatFiles(string directory, List<FileInfo> matFiles)
{
foreach (var file in matFiles)
{
if (!string.IsNullOrEmpty(file.Name) && !string.IsNullOrEmpty(directory) && !string.IsNullOrEmpty(file.FullName))
{
var cloudBlockBlob = this._cloudBlobContainer.GetBlockBlobReference("textures/" + directory + "/" + file.Name);
if (!await cloudBlockBlob.ExistsAsync())
await cloudBlockBlob.UploadFromFileAsync(file.FullName);
}
}
List<Task> tasks = new List<Task>();
foreach (var directory in matFileDirectories)
{
// Get all the files in the directory
var matFiles = new DirectoryInfo(directory).EnumerateFiles().ToList();
// Get the directory name of the files
var matDirectory = Path.GetFileName(Path.GetDirectoryName(matFiles.FirstOrDefault().FullName));
if (matFiles.Count > 0 && !string.IsNullOrEmpty(matDirectory))
{
var task = new Task(() =>this.ProcessMatFiles(matDirectory, matFiles));
tasks.Add(task);
task.Start();
}
}
Task.WaitAll(tasks.ToArray());
With this code, i get the following warning:
Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
What does that mean? How does this affect my code?
I can remove the warning by doing like this:
var task = new Task(async () => await this.ProcessMatFiles());
Is this the correct way to this?