110,534
社区成员
发帖
与我相关
我的任务
分享
private bool OK = false;
private void HttpGet() {
WebClient wc = new WebClient();
wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(wc_DownloadDataCompleted);
wc.DownloadDataAsync(new Uri("http://www.baidu.com"));
}
void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
//当然,也可以在这里做返回的处理
OK = true;
}
//页面的关闭事件
private void Form1_Closing(object sender, CancelEventArgs e)
{
if(!OK)
MessageBox.Show("任务还没有完成,不能关闭程序!");
e.Cancel = !OK;
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// Determine if text has changed in the textbox by comparing to original text.
if (textBox1.Text != strMyOriginalText)
{
// Display a MsgBox asking the user to save changes or abort.
if(MessageBox.Show("Do you want to save changes to your text?", "My Application",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// Cancel the Closing event from closing the form.
e.Cancel = true;
// Call method to save file...
}
}
}