Looking at the System.IO.File class, for example, I see the static Exists method, but I don’t see any ExistsAsync counterpart. I suspect File.Exists could block for quite some time if the file in question is, say, on a network share. Sure, I could always use Task.Run, but that won’t make use of I/O completion ports.
I could ask the same about many other static methods of the File class.
I don’t know why there isn’t a
File.ExistsAsyncmethod. It could be that “another process can potentially do something with the file in between the time you call theExistsmethod and perform another operation on the file, such as Delete” and that catching exceptions is still required to ensure proper function of an application that accesses an existing file.In any case, you could write your own.
…which of course does not use IO Completion to get asynchronous IO…
Update: I think File is generally a convenience wrapper. You can do almost everything that
Fileoffers using other APIs, which do offer asynchronous abilities. In the case ofExists, it doesn’t use anything that could use IO Completion ports, it just calls FindFirstFile and checks for error.