[英]Help with a function that is going out of scope (C#)
I am trying to call CancelAsync
, although webClient
is out of scope. 我试图调用CancelAsync
,虽然webClient
超出范围。
private void Download_Click(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
}
private void Button1_Click(object sender, EventArgs e)
{
webClient.CancelAsync();
}
Could someone show me how webClient.CancelAsync()
could be called from this event handler please 有人可以告诉我如何从这个事件处理程序调用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.