await some functions and continue to run some code while waiting for Task.WhenAll?Why shouldn't all functions be async by default?Second await Statement Inside Function Never RunsAwait multiple async Task while setting max running task at a timeAsp.net mvc5 . async await. wait on task with diff return typesawait call doesn't return call to the caller if the task awaited has a long running CPU operation in itAsync wpf event with 'Task.Factory.StartNew' does not wait for awaitHow run async / await in parallel in JavascriptWhat is difference between put code after await v.s. chain code using ContinueWithShould I await a 'async Task' function if I don't care its return value?ES8 await call isn't waiting for me

Engineer refusing to file/disclose patents

Difference between -| and |- in TikZ

Confusion on Parallelogram

What does the Rambam mean when he says that the planets have souls?

Drawing ramified coverings with tikz

Is there a word to describe the feeling of being transfixed out of horror?

Divine apple island

Is it improper etiquette to ask your opponent what his/her rating is before the game?

How to color a curve

Why do IPv6 unique local addresses have to have a /48 prefix?

How much character growth crosses the line into breaking the character

Have I saved too much for retirement so far?

How should I respond when I lied about my education and the company finds out through background check?

What is the gram­mat­i­cal term for “‑ed” words like these?

Indicating multiple different modes of speech (fantasy language or telepathy)

MAXDOP Settings for SQL Server 2014

Journal losing indexing services

Longest common substring in linear time

Can the Supreme Court overturn an impeachment?

Is it possible to use .desktop files to open local pdf files on specific pages with a browser?

Drawing a topological "handle" with Tikz

Visiting the UK as unmarried couple

How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?

How do I implement a file system driver driver in Linux?



await some functions and continue to run some code while waiting for Task.WhenAll?


Why shouldn't all functions be async by default?Second await Statement Inside Function Never RunsAwait multiple async Task while setting max running task at a timeAsp.net mvc5 . async await. wait on task with diff return typesawait call doesn't return call to the caller if the task awaited has a long running CPU operation in itAsync wpf event with 'Task.Factory.StartNew' does not wait for awaitHow run async / await in parallel in JavascriptWhat is difference between put code after await v.s. chain code using ContinueWithShould I await a 'async Task' function if I don't care its return value?ES8 await call isn't waiting for me













0















There are the following functions.



async Task<int> T1() Console.WriteLine("T1"); return await Task.FromResult(1); 
async Task<string> T2() Console.WriteLine("T2"); return await Task.FromResult("T2");
async Task<char> T3() await Task.Delay(2000); Console.WriteLine("T3"); return await Task.FromResult('A');
async Task<string> T4() Console.WriteLine("T4"); return await Task.FromResult("T4");

// U1, U2, U3, and U4 need to be run right after T1, T2, T3, and T4 respectively
void U1() System.Threading.Thread.Sleep(1000); Console.WriteLine($"After T1");
void U2() System.Threading.Thread.Sleep(4000); Console.WriteLine($"After T2");
void U3() System.Threading.Thread.Sleep(1000); Console.WriteLine($"After T3");
void U4() System.Threading.Thread.Sleep(1000); Console.WriteLine($"After T4");

// TAll() needs to be run as soon as T1, T2, T3, and T4 finished.
void TAll() Console.WriteLine("To be run after T1, T2, T3, T4");

// All() runs after all functions are done.
void All() Console.WriteLine("To be run after U1, U2, U3, U4");


However, the following calls



var t1 = T1().ContinueWith(_ => U1());
var t2 = T2().ContinueWith(_ => U2());
var t3 = T3().ContinueWith(_ => U3());
var t4 = T4().ContinueWith(_ => U4());
await Task.WhenAll(t1, t2, t3, t4);
TAll();

All();


returns




T1
T2
T4
After T1
After T4
T3
After T3
After T2
To be run after T1, T2, T3, T4
To be run after U1, U2, U3, U4


The expected output order is




T1
T2
T4
After T1
After T4
T3
To be run after T1, T2, T3, T4
After T3
After T2
To be run after U1, U2, U3, U4









share|improve this question
























  • You are actually waiting for all continuations to finish not their target tasks...

    – Johnny
    Mar 8 at 7:16











  • If I wait all on T#, the U# will not be called right after T functions are done.

    – ca9163d9
    Mar 8 at 7:22















0















There are the following functions.



async Task<int> T1() Console.WriteLine("T1"); return await Task.FromResult(1); 
async Task<string> T2() Console.WriteLine("T2"); return await Task.FromResult("T2");
async Task<char> T3() await Task.Delay(2000); Console.WriteLine("T3"); return await Task.FromResult('A');
async Task<string> T4() Console.WriteLine("T4"); return await Task.FromResult("T4");

// U1, U2, U3, and U4 need to be run right after T1, T2, T3, and T4 respectively
void U1() System.Threading.Thread.Sleep(1000); Console.WriteLine($"After T1");
void U2() System.Threading.Thread.Sleep(4000); Console.WriteLine($"After T2");
void U3() System.Threading.Thread.Sleep(1000); Console.WriteLine($"After T3");
void U4() System.Threading.Thread.Sleep(1000); Console.WriteLine($"After T4");

// TAll() needs to be run as soon as T1, T2, T3, and T4 finished.
void TAll() Console.WriteLine("To be run after T1, T2, T3, T4");

// All() runs after all functions are done.
void All() Console.WriteLine("To be run after U1, U2, U3, U4");


However, the following calls



var t1 = T1().ContinueWith(_ => U1());
var t2 = T2().ContinueWith(_ => U2());
var t3 = T3().ContinueWith(_ => U3());
var t4 = T4().ContinueWith(_ => U4());
await Task.WhenAll(t1, t2, t3, t4);
TAll();

All();


returns




T1
T2
T4
After T1
After T4
T3
After T3
After T2
To be run after T1, T2, T3, T4
To be run after U1, U2, U3, U4


The expected output order is




T1
T2
T4
After T1
After T4
T3
To be run after T1, T2, T3, T4
After T3
After T2
To be run after U1, U2, U3, U4









share|improve this question
























  • You are actually waiting for all continuations to finish not their target tasks...

    – Johnny
    Mar 8 at 7:16











  • If I wait all on T#, the U# will not be called right after T functions are done.

    – ca9163d9
    Mar 8 at 7:22













0












0








0








There are the following functions.



async Task<int> T1() Console.WriteLine("T1"); return await Task.FromResult(1); 
async Task<string> T2() Console.WriteLine("T2"); return await Task.FromResult("T2");
async Task<char> T3() await Task.Delay(2000); Console.WriteLine("T3"); return await Task.FromResult('A');
async Task<string> T4() Console.WriteLine("T4"); return await Task.FromResult("T4");

// U1, U2, U3, and U4 need to be run right after T1, T2, T3, and T4 respectively
void U1() System.Threading.Thread.Sleep(1000); Console.WriteLine($"After T1");
void U2() System.Threading.Thread.Sleep(4000); Console.WriteLine($"After T2");
void U3() System.Threading.Thread.Sleep(1000); Console.WriteLine($"After T3");
void U4() System.Threading.Thread.Sleep(1000); Console.WriteLine($"After T4");

// TAll() needs to be run as soon as T1, T2, T3, and T4 finished.
void TAll() Console.WriteLine("To be run after T1, T2, T3, T4");

// All() runs after all functions are done.
void All() Console.WriteLine("To be run after U1, U2, U3, U4");


However, the following calls



var t1 = T1().ContinueWith(_ => U1());
var t2 = T2().ContinueWith(_ => U2());
var t3 = T3().ContinueWith(_ => U3());
var t4 = T4().ContinueWith(_ => U4());
await Task.WhenAll(t1, t2, t3, t4);
TAll();

All();


returns




T1
T2
T4
After T1
After T4
T3
After T3
After T2
To be run after T1, T2, T3, T4
To be run after U1, U2, U3, U4


The expected output order is




T1
T2
T4
After T1
After T4
T3
To be run after T1, T2, T3, T4
After T3
After T2
To be run after U1, U2, U3, U4









share|improve this question
















There are the following functions.



async Task<int> T1() Console.WriteLine("T1"); return await Task.FromResult(1); 
async Task<string> T2() Console.WriteLine("T2"); return await Task.FromResult("T2");
async Task<char> T3() await Task.Delay(2000); Console.WriteLine("T3"); return await Task.FromResult('A');
async Task<string> T4() Console.WriteLine("T4"); return await Task.FromResult("T4");

// U1, U2, U3, and U4 need to be run right after T1, T2, T3, and T4 respectively
void U1() System.Threading.Thread.Sleep(1000); Console.WriteLine($"After T1");
void U2() System.Threading.Thread.Sleep(4000); Console.WriteLine($"After T2");
void U3() System.Threading.Thread.Sleep(1000); Console.WriteLine($"After T3");
void U4() System.Threading.Thread.Sleep(1000); Console.WriteLine($"After T4");

// TAll() needs to be run as soon as T1, T2, T3, and T4 finished.
void TAll() Console.WriteLine("To be run after T1, T2, T3, T4");

// All() runs after all functions are done.
void All() Console.WriteLine("To be run after U1, U2, U3, U4");


However, the following calls



var t1 = T1().ContinueWith(_ => U1());
var t2 = T2().ContinueWith(_ => U2());
var t3 = T3().ContinueWith(_ => U3());
var t4 = T4().ContinueWith(_ => U4());
await Task.WhenAll(t1, t2, t3, t4);
TAll();

All();


returns




T1
T2
T4
After T1
After T4
T3
After T3
After T2
To be run after T1, T2, T3, T4
To be run after U1, U2, U3, U4


The expected output order is




T1
T2
T4
After T1
After T4
T3
To be run after T1, T2, T3, T4
After T3
After T2
To be run after U1, U2, U3, U4






c# async-await task






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 7:45









Johnny

3,2101021




3,2101021










asked Mar 8 at 7:08









ca9163d9ca9163d9

8,4062694208




8,4062694208












  • You are actually waiting for all continuations to finish not their target tasks...

    – Johnny
    Mar 8 at 7:16











  • If I wait all on T#, the U# will not be called right after T functions are done.

    – ca9163d9
    Mar 8 at 7:22

















  • You are actually waiting for all continuations to finish not their target tasks...

    – Johnny
    Mar 8 at 7:16











  • If I wait all on T#, the U# will not be called right after T functions are done.

    – ca9163d9
    Mar 8 at 7:22
















You are actually waiting for all continuations to finish not their target tasks...

– Johnny
Mar 8 at 7:16





You are actually waiting for all continuations to finish not their target tasks...

– Johnny
Mar 8 at 7:16













If I wait all on T#, the U# will not be called right after T functions are done.

– ca9163d9
Mar 8 at 7:22





If I wait all on T#, the U# will not be called right after T functions are done.

– ca9163d9
Mar 8 at 7:22












3 Answers
3






active

oldest

votes


















4














You should use async and await rather than ContinueWith. In your case, adding new async methods will simplify the code:



var t1 = T1();
var u1 = InvokeU1(t1);
var t2 = T2();
var u2 = InvokeU2(t2);
var t3 = T3();
var u3 = InvokeU3(t3);
var t4 = T4();
var u4 = InvokeU4(t4);

await Task.WhenAll(t1, t2, t3, t4);
TAll();

await Task.WhenAll(u1, u2, u3, u4);
All();

async Task InvokeU1(Task task) await task; U1();
async Task InvokeU2(Task task) await task; U2();
async Task InvokeU3(Task task) await task; U3();
async Task InvokeU4(Task task) await task; U4();





share|improve this answer






























    3














    The continuation of the task is actually task. In your example your are awaiting on the continuations so "To be run after..." will be logged when all target tasks and all their continuations are done.



    Consider this:



    //target tasks
    var t1 = T1();
    var t2 = T2();
    var t3 = T3();
    var t4 = T4();

    //continuations
    var c1 = t1.ContinueWith(_ => U1());
    var c2 = t2.ContinueWith(_ => U2());
    var c3 = t3.ContinueWith(_ => U3());
    var c4 = t4.ContinueWith(_ => U4());

    await Task.WhenAll(t1, t2, t3, t4);
    TAll();

    await Task.WhenAll(c1, c2, c3, c4);
    All();


    The output will be in line with what you expect.



    Update



    Stephen added a good tip about ContinueWith and I encourage you to use it. However regardless how dangerous ContinueWith is here I tried to explain the problem conceptually.






    share|improve this answer

























    • Great. Is there other ways to do it without using continuewith?

      – ca9163d9
      Mar 8 at 14:33






    • 1





      @ca9163d9: You should not use ContinueWith in real-world code. Use an async method instead.

      – Stephen Cleary
      Mar 8 at 14:45


















    0














    Since you have await Task.WhenAll(t1, t2, t3, t4); this ensures T1(),T2(),T3(),T4() and its associated U1(),U2(),U3(),U4() (order depends upon the thread sleep or task.deley you have mentioned in each of those) to complete before it goes on to execute TALL() and ALL() in the sequence. Hence below two statement is the last to print



    To be run after T1, T2, T3, T4
    To be run after U1, U2, U3, U4





    share|improve this answer






















      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%2f55058356%2fawait-some-functions-and-continue-to-run-some-code-while-waiting-for-task-whenal%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4














      You should use async and await rather than ContinueWith. In your case, adding new async methods will simplify the code:



      var t1 = T1();
      var u1 = InvokeU1(t1);
      var t2 = T2();
      var u2 = InvokeU2(t2);
      var t3 = T3();
      var u3 = InvokeU3(t3);
      var t4 = T4();
      var u4 = InvokeU4(t4);

      await Task.WhenAll(t1, t2, t3, t4);
      TAll();

      await Task.WhenAll(u1, u2, u3, u4);
      All();

      async Task InvokeU1(Task task) await task; U1();
      async Task InvokeU2(Task task) await task; U2();
      async Task InvokeU3(Task task) await task; U3();
      async Task InvokeU4(Task task) await task; U4();





      share|improve this answer



























        4














        You should use async and await rather than ContinueWith. In your case, adding new async methods will simplify the code:



        var t1 = T1();
        var u1 = InvokeU1(t1);
        var t2 = T2();
        var u2 = InvokeU2(t2);
        var t3 = T3();
        var u3 = InvokeU3(t3);
        var t4 = T4();
        var u4 = InvokeU4(t4);

        await Task.WhenAll(t1, t2, t3, t4);
        TAll();

        await Task.WhenAll(u1, u2, u3, u4);
        All();

        async Task InvokeU1(Task task) await task; U1();
        async Task InvokeU2(Task task) await task; U2();
        async Task InvokeU3(Task task) await task; U3();
        async Task InvokeU4(Task task) await task; U4();





        share|improve this answer

























          4












          4








          4







          You should use async and await rather than ContinueWith. In your case, adding new async methods will simplify the code:



          var t1 = T1();
          var u1 = InvokeU1(t1);
          var t2 = T2();
          var u2 = InvokeU2(t2);
          var t3 = T3();
          var u3 = InvokeU3(t3);
          var t4 = T4();
          var u4 = InvokeU4(t4);

          await Task.WhenAll(t1, t2, t3, t4);
          TAll();

          await Task.WhenAll(u1, u2, u3, u4);
          All();

          async Task InvokeU1(Task task) await task; U1();
          async Task InvokeU2(Task task) await task; U2();
          async Task InvokeU3(Task task) await task; U3();
          async Task InvokeU4(Task task) await task; U4();





          share|improve this answer













          You should use async and await rather than ContinueWith. In your case, adding new async methods will simplify the code:



          var t1 = T1();
          var u1 = InvokeU1(t1);
          var t2 = T2();
          var u2 = InvokeU2(t2);
          var t3 = T3();
          var u3 = InvokeU3(t3);
          var t4 = T4();
          var u4 = InvokeU4(t4);

          await Task.WhenAll(t1, t2, t3, t4);
          TAll();

          await Task.WhenAll(u1, u2, u3, u4);
          All();

          async Task InvokeU1(Task task) await task; U1();
          async Task InvokeU2(Task task) await task; U2();
          async Task InvokeU3(Task task) await task; U3();
          async Task InvokeU4(Task task) await task; U4();






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 14:50









          Stephen ClearyStephen Cleary

          286k47482603




          286k47482603























              3














              The continuation of the task is actually task. In your example your are awaiting on the continuations so "To be run after..." will be logged when all target tasks and all their continuations are done.



              Consider this:



              //target tasks
              var t1 = T1();
              var t2 = T2();
              var t3 = T3();
              var t4 = T4();

              //continuations
              var c1 = t1.ContinueWith(_ => U1());
              var c2 = t2.ContinueWith(_ => U2());
              var c3 = t3.ContinueWith(_ => U3());
              var c4 = t4.ContinueWith(_ => U4());

              await Task.WhenAll(t1, t2, t3, t4);
              TAll();

              await Task.WhenAll(c1, c2, c3, c4);
              All();


              The output will be in line with what you expect.



              Update



              Stephen added a good tip about ContinueWith and I encourage you to use it. However regardless how dangerous ContinueWith is here I tried to explain the problem conceptually.






              share|improve this answer

























              • Great. Is there other ways to do it without using continuewith?

                – ca9163d9
                Mar 8 at 14:33






              • 1





                @ca9163d9: You should not use ContinueWith in real-world code. Use an async method instead.

                – Stephen Cleary
                Mar 8 at 14:45















              3














              The continuation of the task is actually task. In your example your are awaiting on the continuations so "To be run after..." will be logged when all target tasks and all their continuations are done.



              Consider this:



              //target tasks
              var t1 = T1();
              var t2 = T2();
              var t3 = T3();
              var t4 = T4();

              //continuations
              var c1 = t1.ContinueWith(_ => U1());
              var c2 = t2.ContinueWith(_ => U2());
              var c3 = t3.ContinueWith(_ => U3());
              var c4 = t4.ContinueWith(_ => U4());

              await Task.WhenAll(t1, t2, t3, t4);
              TAll();

              await Task.WhenAll(c1, c2, c3, c4);
              All();


              The output will be in line with what you expect.



              Update



              Stephen added a good tip about ContinueWith and I encourage you to use it. However regardless how dangerous ContinueWith is here I tried to explain the problem conceptually.






              share|improve this answer

























              • Great. Is there other ways to do it without using continuewith?

                – ca9163d9
                Mar 8 at 14:33






              • 1





                @ca9163d9: You should not use ContinueWith in real-world code. Use an async method instead.

                – Stephen Cleary
                Mar 8 at 14:45













              3












              3








              3







              The continuation of the task is actually task. In your example your are awaiting on the continuations so "To be run after..." will be logged when all target tasks and all their continuations are done.



              Consider this:



              //target tasks
              var t1 = T1();
              var t2 = T2();
              var t3 = T3();
              var t4 = T4();

              //continuations
              var c1 = t1.ContinueWith(_ => U1());
              var c2 = t2.ContinueWith(_ => U2());
              var c3 = t3.ContinueWith(_ => U3());
              var c4 = t4.ContinueWith(_ => U4());

              await Task.WhenAll(t1, t2, t3, t4);
              TAll();

              await Task.WhenAll(c1, c2, c3, c4);
              All();


              The output will be in line with what you expect.



              Update



              Stephen added a good tip about ContinueWith and I encourage you to use it. However regardless how dangerous ContinueWith is here I tried to explain the problem conceptually.






              share|improve this answer















              The continuation of the task is actually task. In your example your are awaiting on the continuations so "To be run after..." will be logged when all target tasks and all their continuations are done.



              Consider this:



              //target tasks
              var t1 = T1();
              var t2 = T2();
              var t3 = T3();
              var t4 = T4();

              //continuations
              var c1 = t1.ContinueWith(_ => U1());
              var c2 = t2.ContinueWith(_ => U2());
              var c3 = t3.ContinueWith(_ => U3());
              var c4 = t4.ContinueWith(_ => U4());

              await Task.WhenAll(t1, t2, t3, t4);
              TAll();

              await Task.WhenAll(c1, c2, c3, c4);
              All();


              The output will be in line with what you expect.



              Update



              Stephen added a good tip about ContinueWith and I encourage you to use it. However regardless how dangerous ContinueWith is here I tried to explain the problem conceptually.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 9 at 8:20

























              answered Mar 8 at 7:26









              JohnnyJohnny

              3,2101021




              3,2101021












              • Great. Is there other ways to do it without using continuewith?

                – ca9163d9
                Mar 8 at 14:33






              • 1





                @ca9163d9: You should not use ContinueWith in real-world code. Use an async method instead.

                – Stephen Cleary
                Mar 8 at 14:45

















              • Great. Is there other ways to do it without using continuewith?

                – ca9163d9
                Mar 8 at 14:33






              • 1





                @ca9163d9: You should not use ContinueWith in real-world code. Use an async method instead.

                – Stephen Cleary
                Mar 8 at 14:45
















              Great. Is there other ways to do it without using continuewith?

              – ca9163d9
              Mar 8 at 14:33





              Great. Is there other ways to do it without using continuewith?

              – ca9163d9
              Mar 8 at 14:33




              1




              1





              @ca9163d9: You should not use ContinueWith in real-world code. Use an async method instead.

              – Stephen Cleary
              Mar 8 at 14:45





              @ca9163d9: You should not use ContinueWith in real-world code. Use an async method instead.

              – Stephen Cleary
              Mar 8 at 14:45











              0














              Since you have await Task.WhenAll(t1, t2, t3, t4); this ensures T1(),T2(),T3(),T4() and its associated U1(),U2(),U3(),U4() (order depends upon the thread sleep or task.deley you have mentioned in each of those) to complete before it goes on to execute TALL() and ALL() in the sequence. Hence below two statement is the last to print



              To be run after T1, T2, T3, T4
              To be run after U1, U2, U3, U4





              share|improve this answer



























                0














                Since you have await Task.WhenAll(t1, t2, t3, t4); this ensures T1(),T2(),T3(),T4() and its associated U1(),U2(),U3(),U4() (order depends upon the thread sleep or task.deley you have mentioned in each of those) to complete before it goes on to execute TALL() and ALL() in the sequence. Hence below two statement is the last to print



                To be run after T1, T2, T3, T4
                To be run after U1, U2, U3, U4





                share|improve this answer

























                  0












                  0








                  0







                  Since you have await Task.WhenAll(t1, t2, t3, t4); this ensures T1(),T2(),T3(),T4() and its associated U1(),U2(),U3(),U4() (order depends upon the thread sleep or task.deley you have mentioned in each of those) to complete before it goes on to execute TALL() and ALL() in the sequence. Hence below two statement is the last to print



                  To be run after T1, T2, T3, T4
                  To be run after U1, U2, U3, U4





                  share|improve this answer













                  Since you have await Task.WhenAll(t1, t2, t3, t4); this ensures T1(),T2(),T3(),T4() and its associated U1(),U2(),U3(),U4() (order depends upon the thread sleep or task.deley you have mentioned in each of those) to complete before it goes on to execute TALL() and ALL() in the sequence. Hence below two statement is the last to print



                  To be run after T1, T2, T3, T4
                  To be run after U1, U2, U3, U4






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 8 at 7:27









                  AsifAsif

                  594




                  594



























                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55058356%2fawait-some-functions-and-continue-to-run-some-code-while-waiting-for-task-whenal%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

                      Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                      Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                      2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived