You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The StorageFile.CreateAsync method currently doesn't open a Stream. This is done on purpose to prevent situations where a Stream is not disposed. However, in certain situations, one wants to atomically create and open the file, e.g. for creating lock files. Files should therefore provide both options.
Discussion
The naming is open, but I'm leaning towards StorageFile.CreateAndOpenAsync(CreationCollisionOption, CancellationToken).
This change also makes sense together with #9, since #9 might add new parameters to the OpenAsync method. This parameter should then be mirrored.
The new method can also be implemented without introducing a breaking change by making it virtual instead of abstract. The default implementation in StorageFile could then call CreateAsync and OpenAsync in order. This is not atomic, but perhaps the best possible implementation for certain file systems.
The text was updated successfully, but these errors were encountered:
Closing for now. See this comment for the reasons.
Additional info:
I initially thought of this feature for the purpose of atomically acquiring a file lock. With FileShare being discarded for now, file locks are basically gone. Therefore, this feature is also less pressing.
With that being said, it might also make sense in other, non file locking related scenarios. If anyone has a need for this feature, please comment. Adding it is still possible (just less pressing for myself right now).
I've now reached a point where I want to have support for a method like this. Even though atomicity cannot be guaranteed, having it is incredibly convenient in most situations. Therefore reopening this issue.
New Feature Proposal
Description
The
StorageFile.CreateAsync
method currently doesn't open aStream
. This is done on purpose to prevent situations where aStream
is not disposed. However, in certain situations, one wants to atomically create and open the file, e.g. for creating lock files. Files should therefore provide both options.Discussion
The naming is open, but I'm leaning towards
StorageFile.CreateAndOpenAsync(CreationCollisionOption, CancellationToken)
.This change also makes sense together with #9, since #9 might add new parameters to the
OpenAsync
method. This parameter should then be mirrored.The new method can also be implemented without introducing a breaking change by making it
virtual
instead ofabstract
. The default implementation inStorageFile
could then callCreateAsync
andOpenAsync
in order. This is not atomic, but perhaps the best possible implementation for certain file systems.The text was updated successfully, but these errors were encountered: