COBCH1926 An AWAIT expression cannot be used within a SYNC block

An AWAIT expression has been used within a SYNC block. This is not allowed.

Resolution:

Correct the code to place the AWAIT expression within an ASYNC method.

Example:

The following example shows an AWAIT expression incorrectly used within a SYNC block, and also an AWAIT expression shown correctly within an ASYNC method.

      $set ilusing"System"
      $set ilusing "System.Threading.Tasks"
      $set sourceformat(variable)
       class-id A.
       method-id Main static.
           *> Demo 1
           invoke type Console::WriteLine("Awaiting call to long operation:");
           declare withAwaitAtCallTask = WithAwaitAtCallAsync()
           invoke withAwaitAtCallTask::Wait()
       end method.

       method-id WithAwaitAtCallAsync() private static async.
           declare o as object = "Hello"
           sync on o
               invoke await type Task::Delay(1000);
           end-sync
       end method.
       end class.