I am currently learning how to use Tasks, async and wait in Windows Store apps ("Metro"). I came across the Task.CurrentId property and try to understand how it works.
According to MSDN, it returns "The integer that has been assigned by the system for the task currently being performed." Therefore, I added the registration of this value to my own registrar, but, to my surprise, none of my test applications ever registered anything except null .
Take a 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 of these identifiers are null . What for? This code really creates tasks, doesn't it? Should they have an identifier?
Sebastian negraszus
source share