I have an application which will upload files. I don't want my application to halt during the file upload, so I want to do the task asynchronously. I have something like this:
class Program
{
static void Main(string[] args)
{
//less than 5 seconds
PrepareUpload();
}
private static async Task PrepareUpload()
{
//processing
await Upload();
//processing
}
private static Task Upload()
{
var task = Task.Factory.StartNew(() => System.Threading.Thread.Sleep(5000));
return task;
}
}
The exceptions are being treated internally, so that is not a problem.
Is it okay to use async/away like a shoot and forget like this?
In a console app, you need to wait. Otherwise, your application will exit, terminating all background threads and asynchronous operations that are in progress.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With