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 9142969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:54:29+00:00 2026-06-17T09:54:29+00:00

I am currently learning how to use Tasks, async and await in Windows Store

  • 0

I am currently learning how to use Tasks, async and await in Windows Store (“Metro”) apps. I stumbled upon the property Task.CurrentId and try to understand how it works.

According to MSDN it returns “An integer that was assigned by the system to the currently-executing task”. So I added logging this value to my custom logger, but to my surprise none of my test apps ever logged anything but null.

Look at this example:

private async void TestButton_Click(object sender, RoutedEventArgs e)
{
    int? id1 = Task.CurrentId;

    await Task.Delay(100);
    int? id2 = Task.CurrentId;

    StorageFolder folder = ApplicationData.Current.LocalFolder;
    StorageFile file = await folder.CreateFileAsync("test.txt", 
        CreationCollisionOption.OpenIfExists);
    int? id3 = Task.CurrentId;

    await FileIO.AppendTextAsync(file, "test");
    int? id4 = Task.CurrentId;

    await DoMoreAsync();
    int? id7 = Task.CurrentId;
}

private async Task DoMoreAsync()
{
    StorageFolder folder = ApplicationData.Current.LocalFolder;
    StorageFile file = await folder.CreateFileAsync("test.txt",
        CreationCollisionOption.OpenIfExists);
    int? id5 = Task.CurrentId;

    await FileIO.AppendTextAsync(file, "test");
    int? id6 = Task.CurrentId;
}

All these ids are null. Why? This code does create tasks, doesn’t it? Shouldn’t they have an id?

  • 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-17T09:54:30+00:00Added an answer on June 17, 2026 at 9:54 am

    Because you’re using async / await, all your Task.CurrentId calls are happening on the UI thread.

    The UI thread is not a Task, so it has a null CurrentId


    If you create a Task, its CurrentId will be set:

    int? idTask = await Task.Run( () => Task.CurrentId );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently learning how to use HTML5 new elements and I stumbled upon
I am currently learning how to use OpenGL for Windows. To check if i
Hi I am currently learning how to use service and notifications in android and
I'm currently learning on how to use the Python optparse module. I'm trying the
I am currently learning the zsh and now I wanted to use strftime but
i am currently learning Zend Framework 1.10 and intend to use Doctrine 2. however
As I'm currently learning to use WCF Services, I am constantly encountering tutorials on
I am currently learning to use Audio Queue Services in iOS. For this, I
Im very new to Objective-C and am currently learning how to use Xcode and
I am currently learning to use the YUI2 DataTable. (I will learn the YUI3

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.