更新:2007 年 11 月
移除使用 add_completed 方法添加的事件处理程序。
MyWebRequest.remove_completed();
备注
与请求相关联的执行器通过调用 completed 方法负责引发事件。在相关联的执行器完成其工作后调用事件处理程序。执行器完成其工作时的状态为:完成、中止或超时。
示例
下面的示例演示如何添加和移除完成事件处理程序。此代码摘自 WebRequest 类概述中的一个完整示例。
// This function adds and removes the
// Web request completed event handler.
function WebRequestCompleted()
{
// Instantiate the WebRequest.
var wRequest = new Sys.Net.WebRequest();
// Set the request Url.
wRequest.set_url(getPage);
// Set the web request completed event handler,
// for processing return data.
wRequest.add_completed(OnWebRequestCompleted);
alert("Added Web request completed handler");
// Remove the web request completed event handler.
// Comment the following two lines if you want to
// use the handler.
wRequest.remove_completed(OnWebRequestCompleted);
alert("Removed handler; the Web request return is not processed.");
// Execute the request.
wRequest.invoke();
}