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

Deferral documentation doesn't state whether it must manually be completed if it is disposed #2035

Closed mqudsi closed 3 weeks ago

mqudsi commented 3 years ago

The documentation on deferrals doesn't state whether this is sufficient:

SomeAction += async (s, e) => {
    using var deferral = e.GetDeferral();
    var bar = await foo();
    e.Result = bar;
    // deferral.Complete();
};

or if the deferral.Complete() line must be commented back in.

i.e. does disposing a deferral also complete it if it hasn't yet been completed?


Document Details

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

MikeHillberg commented 3 years ago

Yes, specifically the Deferral completes automatically in its destructor, same as calling Close/Dispose. But note that in C# the Deferral's destruction won't happen until GC has collected it some random time in the future.

mqudsi commented 3 years ago

Thanks, @MikeHillberg. Note that in my sample above, the deferral is in a using block/statement so it will be disposed immediately at the end of the scope; so if I understand you correctly, there shouldn't be anything waiting on the actual destructor/finalizer.

alvinashcraft commented 3 weeks ago

Thanks for submitting your feedback and we apologize for the delayed response. I see that updates have not been made since the creation of this Issue, so I went ahead and created an internal work item to engage with our engineering folks, find the answers, and resolve this doc bug. The timeline for this may vary, so I will go ahead and close this and circle back when the changes are live.

We have moved to a new feedback system, and I want to ensure that we don't lose access to the feedback in our open issues. Though the Issue will be marked as Closed, we will monitor any replies that come afterwards so treat this like an open Issue. Many thanks.