[英]Is it okay to not await async method call?
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? 是否可以像拍摄一样使用async / away而忘记这样?
In a console app, you need to wait. 在控制台应用程序中,您需要等待。 Otherwise, your application will exit, terminating all background threads and asynchronous operations that are in progress. 否则,您的应用程序将退出,终止正在进行的所有后台线程和异步操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.