MicrosoftDocs / winrt-api

WinRT reference content for developing Microsoft Universal Windows Platform (UWP) apps
Creative Commons Attribution 4.0 International
230 stars 494 forks source link

What are the return values of CopyAndCloseAsync? #2373

Closed leo-hydraulic closed 1 year ago

leo-hydraulic commented 1 year ago

CopyAndCloseAsync returns an IAsyncOperationWithProgress<uint64_t,uint64_t>, presumably containing data about the progress of the operation. What are the two uint64_t values in the template type? The documentation doesn't explain what they are. Are they something like total bytes / bytes copied so far? An explanation would be nice.

Thanks.


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

alvinashcraft commented 1 year ago

Thanks for submitting this issue. This doesn't appear to be documented for CopyAsync either. I'll find out what these values are and update both pages.

leo-hydraulic commented 1 year ago

In time: I did some tests to try to figure out what the values are, and it seems to me that both CopyAsync and CopyAndCloseAsync aren't actually asynchronous, and will block waiting for the copy before returning, even if I don't use "await" or "get()". Is that the case?

alvinashcraft commented 1 year ago

I think it may not be traditional async method. Does it work if you use await CopyAsync().AsTask()?

leo-hydraulic commented 1 year ago

Maybe it does, but I wanted to track the progress of the copy operation. Is it possible to do it with a Task?

alvinashcraft commented 1 year ago

Thanks for the additional context. I reached out to someone from the feature team to see if I can get more info or some sample code for doing what you want.

alvinashcraft commented 1 year ago

Hi @leo-hydraulic. The IAsyncOperationWIthProgress<TResult, TProgress> interface that is returned by the two methods is well-documented here: https://learn.microsoft.com/en-us/uwp/api/windows.foundation.iasyncoperationwithprogress-2?view=winrt-22621. I'll update the two method pages to make sure it's clear that you should go there for more information.

leo-hydraulic commented 1 year ago

IAsyncOperationWIthProgress<TResult, TProgress> is a template class. The TResult and TProgress types are meaningless without an implementation to give them meaning. And the specifics of the "uint64_t"s returned by CopyAsync/CopyAndCloseAsync should be defined there.

A good example of what I mean can be found in the documentation of IOutputStream.WriteAsync:

Returns

IAsyncOperationWithProgress<uint32_t,uint32_t>

The byte writer operation. The first integer represents the number of bytes written. The second integer represents the progress of the write operation.

alvinashcraft commented 1 year ago

Thanks for this additional info with the reference to other docs. I've updated CopyAsync and CopyAndCloseAsync to provide the same information. The changes should be merged and live later today.

Thanks for helping to make the documentation better!