Synchronization context for Task.Delay












1














I could find out that, Task.Run executes always on threads from .NET Framework threads pool (TaskScheduler.Default). I suppose, that it is the same with Task.Delay, but I'm not sure.



MSDN says for Task.Delay only:




Creates a task that will complete after a time delay




Therefore the question: Where (in which synchronization context) runs Task.Delay?










share|improve this question
























  • Have a look at Task vs Thread differences. "(A Task) it's really just "the promise of a result in the future""
    – Liam
    Nov 19 '18 at 15:47


















1














I could find out that, Task.Run executes always on threads from .NET Framework threads pool (TaskScheduler.Default). I suppose, that it is the same with Task.Delay, but I'm not sure.



MSDN says for Task.Delay only:




Creates a task that will complete after a time delay




Therefore the question: Where (in which synchronization context) runs Task.Delay?










share|improve this question
























  • Have a look at Task vs Thread differences. "(A Task) it's really just "the promise of a result in the future""
    – Liam
    Nov 19 '18 at 15:47
















1












1








1


0





I could find out that, Task.Run executes always on threads from .NET Framework threads pool (TaskScheduler.Default). I suppose, that it is the same with Task.Delay, but I'm not sure.



MSDN says for Task.Delay only:




Creates a task that will complete after a time delay




Therefore the question: Where (in which synchronization context) runs Task.Delay?










share|improve this question















I could find out that, Task.Run executes always on threads from .NET Framework threads pool (TaskScheduler.Default). I suppose, that it is the same with Task.Delay, but I'm not sure.



MSDN says for Task.Delay only:




Creates a task that will complete after a time delay




Therefore the question: Where (in which synchronization context) runs Task.Delay?







c# .net task synchronizationcontext






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 15:40

























asked Nov 19 '18 at 15:35









Rekshino

2,7161728




2,7161728












  • Have a look at Task vs Thread differences. "(A Task) it's really just "the promise of a result in the future""
    – Liam
    Nov 19 '18 at 15:47




















  • Have a look at Task vs Thread differences. "(A Task) it's really just "the promise of a result in the future""
    – Liam
    Nov 19 '18 at 15:47


















Have a look at Task vs Thread differences. "(A Task) it's really just "the promise of a result in the future""
– Liam
Nov 19 '18 at 15:47






Have a look at Task vs Thread differences. "(A Task) it's really just "the promise of a result in the future""
– Liam
Nov 19 '18 at 15:47














1 Answer
1






active

oldest

votes


















3














Task.Delay doesn't run anywhere. It just creates a task that completes after the specified time. Unlike Task.Run it's not accepting a delegate of yours to run somewhere. Most tasks won't represent the execution of some method on another thread. Task.Run is one of few methods that do that.






share|improve this answer





















  • For it completes after specified time, it should run specified time, or?
    – Rekshino
    Nov 19 '18 at 15:44










  • @Rekshino It's not "running" anything. It's creating a task that will be marked as completed after the specified time. It's not sitting there running code during that time. It's doing nothing during that time.
    – Servy
    Nov 19 '18 at 15:45










  • I'm reminded of a recent comment :)
    – Liam
    Nov 19 '18 at 15:48










  • @Servy Hmm.. I need to think about Wait() and await for Task.Delay for task, which does not run.
    – Rekshino
    Nov 19 '18 at 15:49






  • 2




    @Rekshino Yes. And that's basically never correct. It's the waiting that does the blocking, not the Delay.
    – Servy
    Nov 19 '18 at 16:00











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377961%2fsynchronization-context-for-task-delay%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Task.Delay doesn't run anywhere. It just creates a task that completes after the specified time. Unlike Task.Run it's not accepting a delegate of yours to run somewhere. Most tasks won't represent the execution of some method on another thread. Task.Run is one of few methods that do that.






share|improve this answer





















  • For it completes after specified time, it should run specified time, or?
    – Rekshino
    Nov 19 '18 at 15:44










  • @Rekshino It's not "running" anything. It's creating a task that will be marked as completed after the specified time. It's not sitting there running code during that time. It's doing nothing during that time.
    – Servy
    Nov 19 '18 at 15:45










  • I'm reminded of a recent comment :)
    – Liam
    Nov 19 '18 at 15:48










  • @Servy Hmm.. I need to think about Wait() and await for Task.Delay for task, which does not run.
    – Rekshino
    Nov 19 '18 at 15:49






  • 2




    @Rekshino Yes. And that's basically never correct. It's the waiting that does the blocking, not the Delay.
    – Servy
    Nov 19 '18 at 16:00
















3














Task.Delay doesn't run anywhere. It just creates a task that completes after the specified time. Unlike Task.Run it's not accepting a delegate of yours to run somewhere. Most tasks won't represent the execution of some method on another thread. Task.Run is one of few methods that do that.






share|improve this answer





















  • For it completes after specified time, it should run specified time, or?
    – Rekshino
    Nov 19 '18 at 15:44










  • @Rekshino It's not "running" anything. It's creating a task that will be marked as completed after the specified time. It's not sitting there running code during that time. It's doing nothing during that time.
    – Servy
    Nov 19 '18 at 15:45










  • I'm reminded of a recent comment :)
    – Liam
    Nov 19 '18 at 15:48










  • @Servy Hmm.. I need to think about Wait() and await for Task.Delay for task, which does not run.
    – Rekshino
    Nov 19 '18 at 15:49






  • 2




    @Rekshino Yes. And that's basically never correct. It's the waiting that does the blocking, not the Delay.
    – Servy
    Nov 19 '18 at 16:00














3












3








3






Task.Delay doesn't run anywhere. It just creates a task that completes after the specified time. Unlike Task.Run it's not accepting a delegate of yours to run somewhere. Most tasks won't represent the execution of some method on another thread. Task.Run is one of few methods that do that.






share|improve this answer












Task.Delay doesn't run anywhere. It just creates a task that completes after the specified time. Unlike Task.Run it's not accepting a delegate of yours to run somewhere. Most tasks won't represent the execution of some method on another thread. Task.Run is one of few methods that do that.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 15:43









Servy

177k18234349




177k18234349












  • For it completes after specified time, it should run specified time, or?
    – Rekshino
    Nov 19 '18 at 15:44










  • @Rekshino It's not "running" anything. It's creating a task that will be marked as completed after the specified time. It's not sitting there running code during that time. It's doing nothing during that time.
    – Servy
    Nov 19 '18 at 15:45










  • I'm reminded of a recent comment :)
    – Liam
    Nov 19 '18 at 15:48










  • @Servy Hmm.. I need to think about Wait() and await for Task.Delay for task, which does not run.
    – Rekshino
    Nov 19 '18 at 15:49






  • 2




    @Rekshino Yes. And that's basically never correct. It's the waiting that does the blocking, not the Delay.
    – Servy
    Nov 19 '18 at 16:00


















  • For it completes after specified time, it should run specified time, or?
    – Rekshino
    Nov 19 '18 at 15:44










  • @Rekshino It's not "running" anything. It's creating a task that will be marked as completed after the specified time. It's not sitting there running code during that time. It's doing nothing during that time.
    – Servy
    Nov 19 '18 at 15:45










  • I'm reminded of a recent comment :)
    – Liam
    Nov 19 '18 at 15:48










  • @Servy Hmm.. I need to think about Wait() and await for Task.Delay for task, which does not run.
    – Rekshino
    Nov 19 '18 at 15:49






  • 2




    @Rekshino Yes. And that's basically never correct. It's the waiting that does the blocking, not the Delay.
    – Servy
    Nov 19 '18 at 16:00
















For it completes after specified time, it should run specified time, or?
– Rekshino
Nov 19 '18 at 15:44




For it completes after specified time, it should run specified time, or?
– Rekshino
Nov 19 '18 at 15:44












@Rekshino It's not "running" anything. It's creating a task that will be marked as completed after the specified time. It's not sitting there running code during that time. It's doing nothing during that time.
– Servy
Nov 19 '18 at 15:45




@Rekshino It's not "running" anything. It's creating a task that will be marked as completed after the specified time. It's not sitting there running code during that time. It's doing nothing during that time.
– Servy
Nov 19 '18 at 15:45












I'm reminded of a recent comment :)
– Liam
Nov 19 '18 at 15:48




I'm reminded of a recent comment :)
– Liam
Nov 19 '18 at 15:48












@Servy Hmm.. I need to think about Wait() and await for Task.Delay for task, which does not run.
– Rekshino
Nov 19 '18 at 15:49




@Servy Hmm.. I need to think about Wait() and await for Task.Delay for task, which does not run.
– Rekshino
Nov 19 '18 at 15:49




2




2




@Rekshino Yes. And that's basically never correct. It's the waiting that does the blocking, not the Delay.
– Servy
Nov 19 '18 at 16:00




@Rekshino Yes. And that's basically never correct. It's the waiting that does the blocking, not the Delay.
– Servy
Nov 19 '18 at 16:00


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377961%2fsynchronization-context-for-task-delay%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory