private async void button1_Click(object sender, EventArgs e) { var maxValue = 200; var result = await SumAsync(maxValue); MessageBox.Show(this, result.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } private async Task<string> SumAsync(int maxValue) { string result = string.Empty; await Task.Run(() => { for (int i = 0; i<maxValue; i++) { result += i.ToString() + ","; Thread.Sleep(100); } }); return result; }
标签:Task,C#,maxValue,private,int,result,async,方法 From: https://www.cnblogs.com/z5337/p/17816295.html