示例#1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            var worker = new MyWorker();

            worker.NEVER_DO_THIS();
            MessageBox.Show("NEVER returned.");
        }
示例#2
0
        private async void ButtonSimple_Click(object sender, EventArgs e)
        {
            ButtonSimple.Enabled = false;
            progressBar.Style    = ProgressBarStyle.Marquee;

            var worker = new MyWorker();
            await worker.DoSomethingAsync();

            progressBar.Style    = ProgressBarStyle.Blocks;
            ButtonSimple.Enabled = true;
        }
示例#3
0
 private async void ButtonFaulty_Click(object sender, EventArgs e)
 {
     try
     {
         var worker = new MyWorker();
         await worker.FaultyMethod();
     }
     catch (MyWorkerException x)
     {
         MessageBox.Show(x.Message);
     }
 }
示例#4
0
        private async void bGetResult_Click(object sender, EventArgs e)
        {
            var worker = new MyWorker();

            string result;

            result = await worker.GetAnswerAsync();

            int randomSum =
                await worker.GetRandomNumberAsync()
                +
                await worker.GetRandomNumberAsync();

            MessageBox.Show(result);
        }