簡體   English   中英

幫助超出范圍的函數(C#)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM