Will a C# console app wait for all task.runs to finish? [duplicate]
This question already has an answer here:
Running multiple async tasks and waiting for them all to complete
8 answers
I have a console app that runs a whole bunch of things via task.run
. I need all of those things to complete before the app terminates. The main line code just runs off the end of main. Will the process shutdown wait for all my task.runs
to complete or do I have to wire that up myself. If so does anybody have any suggestions.
c# asynchronous
marked as duplicate by Igor
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 12 '18 at 17:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Running multiple async tasks and waiting for them all to complete
8 answers
I have a console app that runs a whole bunch of things via task.run
. I need all of those things to complete before the app terminates. The main line code just runs off the end of main. Will the process shutdown wait for all my task.runs
to complete or do I have to wire that up myself. If so does anybody have any suggestions.
c# asynchronous
marked as duplicate by Igor
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 12 '18 at 17:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Since tasks will run on background threads (i am ignoring other mechanisms to achieve concurrent/async behavior here), your program/process will not wait for them to finish before terminating. Rather, when your main thread terminates (more precisely, when the last foreground thread terminates), all still running background threads (your tasks) will simply be killed off unceremoniously...
– elgonzo
Nov 12 '18 at 17:33
add a comment |
This question already has an answer here:
Running multiple async tasks and waiting for them all to complete
8 answers
I have a console app that runs a whole bunch of things via task.run
. I need all of those things to complete before the app terminates. The main line code just runs off the end of main. Will the process shutdown wait for all my task.runs
to complete or do I have to wire that up myself. If so does anybody have any suggestions.
c# asynchronous
This question already has an answer here:
Running multiple async tasks and waiting for them all to complete
8 answers
I have a console app that runs a whole bunch of things via task.run
. I need all of those things to complete before the app terminates. The main line code just runs off the end of main. Will the process shutdown wait for all my task.runs
to complete or do I have to wire that up myself. If so does anybody have any suggestions.
This question already has an answer here:
Running multiple async tasks and waiting for them all to complete
8 answers
c# asynchronous
c# asynchronous
edited Nov 12 '18 at 20:42
marc_s
580k13011181266
580k13011181266
asked Nov 12 '18 at 17:25
pm100pm100
25.4k1658104
25.4k1658104
marked as duplicate by Igor
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 12 '18 at 17:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Igor
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 12 '18 at 17:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Since tasks will run on background threads (i am ignoring other mechanisms to achieve concurrent/async behavior here), your program/process will not wait for them to finish before terminating. Rather, when your main thread terminates (more precisely, when the last foreground thread terminates), all still running background threads (your tasks) will simply be killed off unceremoniously...
– elgonzo
Nov 12 '18 at 17:33
add a comment |
Since tasks will run on background threads (i am ignoring other mechanisms to achieve concurrent/async behavior here), your program/process will not wait for them to finish before terminating. Rather, when your main thread terminates (more precisely, when the last foreground thread terminates), all still running background threads (your tasks) will simply be killed off unceremoniously...
– elgonzo
Nov 12 '18 at 17:33
Since tasks will run on background threads (i am ignoring other mechanisms to achieve concurrent/async behavior here), your program/process will not wait for them to finish before terminating. Rather, when your main thread terminates (more precisely, when the last foreground thread terminates), all still running background threads (your tasks) will simply be killed off unceremoniously...
– elgonzo
Nov 12 '18 at 17:33
Since tasks will run on background threads (i am ignoring other mechanisms to achieve concurrent/async behavior here), your program/process will not wait for them to finish before terminating. Rather, when your main thread terminates (more precisely, when the last foreground thread terminates), all still running background threads (your tasks) will simply be killed off unceremoniously...
– elgonzo
Nov 12 '18 at 17:33
add a comment |
2 Answers
2
active
oldest
votes
If you have an array of tasks, you can wait for all of them to complete using the
Task.WaitAll(tasks_array);
add a comment |
On a console app, the process shutdown will not wait for your tasks to finish. It calls ExitProcess, which effectively terminates all threads, including the thread pool that services the Tasks.
As @Ryan Pierce Willems wrote, you need to call Task.WaitAll to make sure you wait for all tasks to complete.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you have an array of tasks, you can wait for all of them to complete using the
Task.WaitAll(tasks_array);
add a comment |
If you have an array of tasks, you can wait for all of them to complete using the
Task.WaitAll(tasks_array);
add a comment |
If you have an array of tasks, you can wait for all of them to complete using the
Task.WaitAll(tasks_array);
If you have an array of tasks, you can wait for all of them to complete using the
Task.WaitAll(tasks_array);
edited Nov 12 '18 at 17:32
D-Shih
26.3k61531
26.3k61531
answered Nov 12 '18 at 17:27
Ryan Pierce WilliamsRyan Pierce Williams
44719
44719
add a comment |
add a comment |
On a console app, the process shutdown will not wait for your tasks to finish. It calls ExitProcess, which effectively terminates all threads, including the thread pool that services the Tasks.
As @Ryan Pierce Willems wrote, you need to call Task.WaitAll to make sure you wait for all tasks to complete.
add a comment |
On a console app, the process shutdown will not wait for your tasks to finish. It calls ExitProcess, which effectively terminates all threads, including the thread pool that services the Tasks.
As @Ryan Pierce Willems wrote, you need to call Task.WaitAll to make sure you wait for all tasks to complete.
add a comment |
On a console app, the process shutdown will not wait for your tasks to finish. It calls ExitProcess, which effectively terminates all threads, including the thread pool that services the Tasks.
As @Ryan Pierce Willems wrote, you need to call Task.WaitAll to make sure you wait for all tasks to complete.
On a console app, the process shutdown will not wait for your tasks to finish. It calls ExitProcess, which effectively terminates all threads, including the thread pool that services the Tasks.
As @Ryan Pierce Willems wrote, you need to call Task.WaitAll to make sure you wait for all tasks to complete.
answered Nov 12 '18 at 17:31
NickNick
2,0481213
2,0481213
add a comment |
add a comment |
Since tasks will run on background threads (i am ignoring other mechanisms to achieve concurrent/async behavior here), your program/process will not wait for them to finish before terminating. Rather, when your main thread terminates (more precisely, when the last foreground thread terminates), all still running background threads (your tasks) will simply be killed off unceremoniously...
– elgonzo
Nov 12 '18 at 17:33