0

I have two long processes that are inside a Task.Run block that I want to run concurrently and capture any exceptions that may occur. I don't want to wait for these tasks to complete and I want to avoid deadlocks so I added ConfigureAwait(false). My first question is how do I execute both methods without waiting and handle the exception for either one? Currently my code looks like this:

Task.Run(async () =>
        {
            try
            {
                EmailTicket();
                PostETicket();
            }
            catch(Exception ex)
            {

            }

        }).ConfigureAwait(false);

If I place await before EmailTicket() and PostETicket() then only method catches the exception and the process ends. If I don't await for the process like above, will I run into any issues?

GH DevOps
  • 305
  • 1
  • 11
  • 1
    There's no point in configuring an await if you never actually await. You're configuring something you're not doing, so it's not accomplishing anything. There's also no point in making a lambda async if you're not going to await anything. – Servy Jul 23 '20 at 14:34
  • @Servy so as long as I don't await, I won't run into any deadlocks? – GH DevOps Jul 23 '20 at 14:50
  • There are lots of ways of writing code that deadlocks without using `await`. All I said is configuring await is pointless if you're not awaiting the returned value. – Servy Jul 23 '20 at 15:25
  • Do you want the `PostETicket` to run after the completion of `EmailTicket`, or both of them to run concurrently? – Theodor Zoulias Jul 23 '20 at 16:24
  • Both to run concurrently without waiting – GH DevOps Jul 23 '20 at 17:14

0 Answers0