Skip to content

5 Comments

  1. The async Keyword and Thrown Exceptions - Stiller on Software
    December 23, 2012 @ 4:16 pm

    […] a similar post on the await keyword can be found here. Share this:FacebookTwitterLinkedInMoreEmailPrintDiggRedditStumbleUponTumblrPinterest This entry […]

    Reply

  2. Boaz
    July 2, 2015 @ 8:55 am

    Hi,

    “await asyncTest.ProcessAsync2(null);” will not throw an exception unless you add Thread.Sleep(200);

    The reason is that the program is finished execution before the async operion raise an exception

    Reply

    • Eran Stiller
      July 2, 2015 @ 9:06 am

      Hi Boaz,
      Actually no. It will throw the exception without any need for “Thread.Sleep()” since “await” itself does the wait. I suspect that the issue you are seeing is that you are not waiting for the asynchronous method encapsulating the “await” itself to finish, thus causing the program to terminate before it reaches this line.
      As a side note, please be aware that using “Thread.Sleep()” for synchronization is not a good practice. It would have been better to do something like this:

      static void Main()
      {
      Do().GetAwaiter().GetResult();
      }

      static async Task Do()
      {
      var asyncTest = new AsyncClass();
      await asyncTest.ProcessAsync2(null);

      }

      Reply

  3. Patrick Fischer
    January 30, 2017 @ 5:57 pm

    HI,

    You wrote:
    “…and it does require the await keyword which is limited only to methods marked with async…”

    Surely it should be:

    “…and it does not require the await keyword which is limited only to methods marked with async….”

    Reply

    • Eran Stiller
      January 30, 2017 @ 8:50 pm

      Yes, you are absolutely correct. Just fixed it.
      Thank you!

      Reply

Have an Opinion?