I`m making my way trough async programming in C#.
I often await a Task that does some stuff that doesn”t necessarley return a value (uploading a file on cloud or updating a line in a database)
an example is:
public async Task UploadFileAsync(string filePath, string destBlobFolder)
{
await blobClient.UploadAsync(filePath, dest)
}
in the caller method i often do
var upload = await UploadFileAsync(file, destination)
but I started having the necessity to understand if the task came to completion or not so I am now using this very odd way of capturing a return string to check if the async method is completed or not:
public async Task<string> UploadFileAsync(string filePath, string destBlobFolder)
{
try{
await blobClient.UploadAsync(fs, Options)
return "complete"
}
catch (exception ex)
return "error"
}
and in the caller method I check if the var upload == "error" or "complete"
.
I am pretty sure that this is not the way to work so I was looking for a more elegant way of doing this.
(same scenario if I have to update a local sqlite database.)
1