Consider the following code
async Task<int> foo() { await Task.Delay(1000); return 42; } ... // OPTION 1 Task t = Task.Factory.StartNew(foo, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); t.Wait(); ... // OPTION 2 Task t = foo(); t.Wait()
Questions
What is the significant difference between the two call options?
In option 1. Assume that I override the default TaskScheduler. To wait in the foo method - which TaskScheduler will be used? Will he use the default value or the value specified in the parameter to specify the father?
, , " 1" , foo(), Task<Task<int>>. .Wait() , , ( Task.Delay).
foo()
Task<Task<int>>
.Wait()
Task.Delay
TaskScheduler, , , , . , , , .
TaskScheduler
, , , , .
Source: https://habr.com/ru/post/1547057/More articles:Quota, lost files and downloads using a service account with the Google Drive API - google-drive-sdkMigrating an Asp.net database, what is the Down method used for? - asp.net-mvc-4List of inviting UAC triggers? - windowsWhy is the Windows UAC icon displayed for my program on some PCs, but not for others? - windowsWhere to get binaries with uitelist? - uacCannot run c / C ++ codes in code :: blocks 13.12 on linuxmint 17: Status 255 - cplaying audio range in html5 - html5Difference between Elasticsearch range query and range filter - elasticsearchTwilio - Outgoing call - playing DTMF tones - restEmber-CLI routing: changed the route / pattern structure, but the assembly does not recognize the changes? - ember.jsAll Articles