示例#1
0
        // An event is the only type of void that can be async
        private async void BtnAsyncClicked(object sender, EventArgs e)
        {
            ClearScreen();
            Stopwatch watch = Stopwatch.StartNew();

            await Method1Async();
            await Method2Async();
            await Method3Async();
            await Method4Async();

            EnergizerBunny bunny = await GetBunnyAsync();

            TxtResult.Text += bunny.ToString();
            TxtResult.Text += $"{Environment.NewLine}Elapsed time: {watch.ElapsedMilliseconds}";
        }
示例#2
0
        private void BtnSyncClicked(object sender, EventArgs e)
        {
            ClearScreen();
            Stopwatch watch = Stopwatch.StartNew();

            Method1();
            Method2();
            Method3();
            Method4();

            EnergizerBunny bunny = GetBunny();

            TxtResult.Text += bunny.ToString();
            TxtResult.Text += $"{Environment.NewLine}Elapsed time: {watch.ElapsedMilliseconds}";
        }