Is it safe not to wait inside the block?

In this code, is it safe not to wait for CopyToAsync or can the stream be deleted before the actual copy?

 public Task SaveAsync(Stream source, string filepath) { using (var file = File.OpenWrite(filepath)) { return source.CopyToAsync(file); } } 
+5
source share
1 answer

No, it is unsafe if you do not expect, then file will be deleted until the copy operation is completed.

+7
source

Source: https://habr.com/ru/post/1247566/


All Articles