This is my current code:
public static void DownloadFile(string _url, string _destination)
{
//Method for downloading files from the internet
//First argument is a full link from the internet where that file is stored
//Second argument is a full destination where user wants to store that downloaded file with file extension
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);
request.Timeout = 5000;
using (WebResponse response = (HttpWebResponse)request.GetResponse())
{
using (FileStream stream = new FileStream(_destination, FileMode.Create, FileAccess.Write))
{
response.GetResponseStream().CopyTo(stream);
}
response.Close();
}
}
public static async void DownloadFileAsync(string _url, string _destination)
{
await Task.Run(() => DownloadFile(_url, _destination));
}
And when I use just DownloadFile method in my main application, everything is working fine. But when I use DownloadFileAsync method it just creates my pdf file but it has 0 kB. Can anyone tell me what am I doing wrong?


















