[英]Help with a function that is going out of scope (C#)
我試圖調用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()
您需要將WebClient
存儲在類中的字段中。
class ....
{
WebClient webClient;
private void Download_Click(object sender, EventArgs e)
{
webClient = new WebClient();
}
private void Button1_Click(object sender, EventArgs e)
{
webClient.CancelAsync();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.