Open-XML-SDK
Open-XML-SDK copied to clipboard
Writing asynchronously with OpenXmlWriter
The OpenXmlWriter doesn't appear to have any async overloads.
Is it not possible to write in a asynchronous fashion?
I'm not sure what would be involved, but happy to take any contributions here. One bottleneck is that I'm not sure if the System.IO.Packaging provides async overloads - that would need to be supported before we can do much with async I think. We may be able to some, but I think we'd need to identify what should be async and the work involved there.
I'm referring to the OpenXmlWriter here though.
I see that the OpenXmlWriter is implemented by OpenXmlPartWriter, which delegates calls to a regular System.Xml.XmlWriter, which does have async overloads for all write operations such as WriteStartElementAsync, WriteAttributeStringAsync, etc...
So it should be possible to add async overloads to the OpenXmlWriter class as well.
https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmlwriter?view=net-5.0#methods shows the async methods.
We'd be happy to accept a PR for this. The next major release will be in a week, and it could potentially be added in that release if reviewed quickly.
I'd like to see a list of which APIs we should add and to which types. Sounds like a starting list of types may be:
- OpenXmlWriter and derived (such as OpenXmlPartWriter)
- OpenXmlReader and derived (such as OpenXmlPartReader)
Are there others that would make sense for async?
@twsouthwick , unfortunately I don't have enough time at the moment but I'll keep in mind that you accept PRs and may come back to it later. I haven't done the analysis of all the classes that could to be made async. I suppose it doesn't all need to be added at the same time... I guess it's a matter of finding all of the IO operations, for which .NET provides async overloads. One potential problem is that adding async overloads can cause duplicate code for the sync and async paths. One mitigation is to do sync over async, but I believe it has its own problems.