Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8845691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:47:48+00:00 2026-06-14T11:47:48+00:00

According to Likness (p. 164, Building Windows 8 Apps with C# and XAML), When

  • 0

According to Likness (p. 164, “Building Windows 8 Apps with C# and XAML”), “When performing asynchronous tasks, you must ask for a deferral.”

So if I’m not taking him out of context, this code:

private async Task<System.Collections.Generic.KeyValuePair<string, string>> SelectAContactForASlot()
{
    KeyValuePair<string, string> kvp; 
    var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker();
    contactPicker.CommitButtonText = "Select";
    var contact = await contactPicker.PickSingleContactAsync();
    if (contact != null)
    {
        kvp = new KeyValuePair<string, string>(contact.Name, contact.Emails[0].ToString());
        return kvp;
    }
    return kvp = new KeyValuePair<string, string>("No Name found", "No email found");
}

…should be this instead:

private async Task<System.Collections.Generic.KeyValuePair<string, string>> SelectAContactForASlot()
{
    var deferral = e.SuspendingOperation.GetDeferral();
    KeyValuePair<string, string> kvp; 
    var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker();
    contactPicker.CommitButtonText = "Select";
    var contact = await contactPicker.PickSingleContactAsync();
    if (contact != null)
    {
        kvp = new KeyValuePair<string, string>(contact.Name, contact.Emails[0].ToString());
        return kvp;
    }
    return kvp = new KeyValuePair<string, string>("No Name found", "No email found");
    deferral.Complete();
}

Correct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:47:50+00:00Added an answer on June 14, 2026 at 11:47 am

    Remember that an async method returns when it hits an await and has to (asynchronously) wait.

    You need a deferral when you await an operation from an async void method that must complete before it returns. This kind of “event” is really a command. E.g., “the mouse moved” is just an event – the system doesn’t care whether or not you handle the event. But “suspend” is a command – the system assumes that when you return from the command, you are done getting ready to be suspended. In this case, deferrals are necessary to inform the system that even though you’re returning, you’re not done yet.

    Similarly, you need a deferral if you have a background task that has an async implementation of Run. Because when Run returns, your background task is considered done, and you need a way to say you’re not really done yet.

    You can tell if an event handler supports this by the presence of a GetDeferral method. For example, Suspending supports deferral because SuspendingEventArgs has a SuspendingOperation property which has a GetDeferral method. In the background task scenario (i.e., you have an async void Run), you can call GetDeferral on the IBackgroundTaskInstance passed into Run.

    Your example of SelectAContactForASlot returns Task, so it doesn’t need the deferral.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to a specific row value (Type), I must use a TextBox or a
According to this MSDN article , you should not catch general exceptions. I'm sure
According to this article I know, that DateTimePicker control does not reflect CurrentUICulture So,
According to the docs: You should not override init. You are discouraged from overriding
According to what I've heard, integer values that are not the processor's word size
According to Microsoft , you must sign your ClickOnce application. But it seems to
According to MDN documentation for JSON.stringify : Properties of non-array objects are not guaranteed
According to the Android docs Intent extra name must have a package prefix. I've
according to https://developers.google.com/web-toolkit/doc/latest/DevGuideUiPanels#Standards I 'm not suppose to use DockPanel, VerticalPanel, HorizontalPanel. But Those
According to HTML5 Rocks , WebGL is actually a 2D API, not a 3D

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.