dotnet / dotnet/dotnet-api-docs
no async on file open
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
Nowadays .NET provides good async [e.g. ReadToEndAsync() method] so caller can complete other work[=good], but the initial file open has no such support [=bad]. The example given reflects this whereas the actual setup of the concrete FileStream potentially takes LOTS longer [think a UNC network path of \\DICKPC\Work\sub1\sub2\myfile.txt] potentially involving [multiple] network round-trips but even if local (e.g. NAS/SAN mapped drive Z:\sub1\sub2\myfile.txt) will incur much physical I/O during which time the calling thread will be blocked which will impair/infuriate GUI uses where the main thread is being used.
IMHO simply saying that developer should always fire off secondary thread (e.g. never use WPF thread) is still insufficient. It may well be that calling thread is also in a crucial section and inappropriate to have to use a slave task (think context switch overhead) to do such grunt work.
My contention is that constructor work should always be rapid and that any hard work (such as walking network/filestore hierarchy) should be subject to a downstream operation such as the first actual I/O (such as ReadToEndAsync). It follows that the FileNotFound exception should NOT be thrown during constructor, but during that first ReadXXX operation.
I recognise that this ain't the ways Windows / .NET has done things historically, and needs NEW code (constructors,methods et al), but as filesystem is so important this aspect should be covered urgently. Heck even database traffic separates work into up-front and downstream handling.
Granted my beef isn't with the docs/practices but with underlying environment. PLEASE don't just say repost to another forum within MS but you [Bill Wagner, dotnet-api-doc et al] actually pass to the PM/architects that dream this stuff! Thanks
---
#### Document Details
⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*
* ID: 71cfcc09-2999-9687-9dc5-bc8140089b22
* Version Independent ID: 309ad78b-2ed6-f5a7-0f37-20f1f8f31c86
* Content: [StreamReader.ReadToEndAsync Method (System.IO)](https://docs.microsoft.com/en-us/dotnet/api/system.io.streamreader.readtoendasync?view=netframework-4.7.2)
* Content Source: [xml/System.IO/StreamReader.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.IO/StreamReader.xml)
* Product: **dotnet-api**
* GitHub Login: @dotnet-bot
* Microsoft Alias: **dotnetcontent**
Contributor guide
Assessment
This issue has not been assessed yet.