我正在尝试拨打CancelAsync
,但webClient
超出了范围。
private void Download_Click(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
}
private void Button1_Click(object sender, EventArgs e)
{
webClient.CancelAsync();
}
有人可以告诉我如何从这个事件处理程序中调用webClient.CancelAsync()
答案 0 :(得分:6)
您需要将WebClient
存储在班级的字段中。
答案 1 :(得分:3)
class ....
{
WebClient webClient;
private void Download_Click(object sender, EventArgs e)
{
webClient = new WebClient();
}
private void Button1_Click(object sender, EventArgs e)
{
webClient.CancelAsync();
}