AWAIT

Wait for an asynchronous task to complete

 

WNSupported in Synergy .NET on Windows

 

 

AWAIT task

Arguments

task

An expression that returns a task of the type System.Threading.Tasks.Task or System.Threading.Tasks.Task<>.

Discussion

The AWAIT statement can only be used in a method or lambda marked as ASYNC. Within that restriction, it can be used anywhere an expression can be used. If AWAIT is not present, the method or lambda is not asynchronous. See Asynchronous processing (.NET) for more information.

.NET Framework 4.5 or higher is required to support asynchronous processing.

Examples

The following program gets weather alerts for different states based on the day of the week.

public async method clickit, void
proc
    data stockPrice, double 
    stockPrice = 123.45;

     data wc, @WebClient
      wc = new WebClient()

    data dt, DateTime
    dt = DateTime.Parse("03-18-2012")

    case (dt.DayOfWeek) of
    begincase
      DayOfWeek.Monday:
      begin
        WriteLinePageTitle(await wc.DownloadStringTaskAsync(new
  &         Uri("http://www.weather.gov/alerts-beta/wa.php?x=1")));
        stockPrice += 1.25;
      end
      DayOfWeek.Tuesday:
      begin
        WriteLinePageTitle(await wc.DownloadStringTaskAsync(new
  &         Uri("http://www.weather.gov/alerts-beta/or.php?x=1")));
        stockPrice *= 1.04;
      end
      DayOfWeek.Wednesday:
      begin
        WriteLinePageTitle(await wc.DownloadStringTaskAsync(new
  &         Uri("http://www.weather.gov/alerts-beta/ca.php?x=1")));
        stockPrice -= 0.58;
      end
      DayOfWeek.Thursday:
      begin
        WriteLinePageTitle(await wc.DownloadStringTaskAsync(new
  &         Uri("http://www.weather.gov/alerts-beta/nv.php?x=1")));
        stockPrice *= 0.99;
      end
      DayOfWeek.Friday:
      begin
        WriteLinePageTitle(await wc.DownloadStringTaskAsync(new
  &         Uri("http://www.weather.gov/alerts-beta/az.php?x=1")));
        stockPrice += 0.79;
      end
      DayOfWeek.Saturday:
      begin
        WriteLinePageTitle(await wc.DownloadStringTaskAsync(new
  &         Uri("http://www.weather.gov/alerts-beta/ut.php?x=1")));
        stockPrice += 1.8;
      end
      DayOfWeek.Sunday:
      begin
        WriteLinePageTitle(await wc.DownloadStringTaskAsync(new
  &         Uri("http://www.weather.gov/alerts-beta/nm.php?x=1")));
        stockPrice /= 1.2;
      end
    endcase
end