I am trying to use Aync method. It's working in a way. But it's not working in some other context.
Working example
dropBox.DownloadFileAsync(csvEntry.Path)
.ContinueWith(task =>
{
// Save file to "C:\Spring Social.txt"
using (FileStream fileStream = new FileStream(tempCsvPath, FileMode.Create))
{
fileStream.Write(task.Result.Content, 0, task.Result.Content.Length);
}
});
Instead of saving the file, I am trying to return the byte array in the following way. But it's not working. It is returning null.
byte[] returnArray = null;
dropbox.DownloadFileAsync(filePath)
.ContinueWith(task =>
{
returnArray = new byte[task.Result.Content.Length];
task.Result.Content.CopyTo(returnArray, 0);
});
return returnArray;
Can somebody correct me?
Thanks