我有一个似乎永远不会完成的ac#异步方法.它通过委托调用并创建一个表单.如果我删除委托或表单创建它工作正常.任何见解将不胜感激!代码如下:
public delegate Task<bool> TaskDel();
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Tag = (TaskDel)taskAsync;
}
private async void button1_Click(object sender, EventArgs e)
{
// if I don't use a delegate here there is no problem.
await Task.Run(() => ((sender as Button).Tag as TaskDel)());
}
public async Task<bool> taskAsync()
{
await new HttpClient().GetStringAsync(URL);
Form form = new Form(); // if I remove this line method works.
await new HttpClient().GetStringAsync(URL);
return true; // as is, never reaches …Run Code Online (Sandbox Code Playgroud)