如何解除 DocumentComplete 处理程序的绑定?
我有以下代码:
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Action1);
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Action2);
工作得很好。
但它们似乎每次任何页面下载完成时都会触发。 尽管我希望它们每个页面只触发一次。 说 Action1 代表 Page1,Action2 代表 Page2 等等。
我尝试添加一个像这样的空处理程序:
void StopDoingStuff(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Application.DoEvents();
}
但似乎 C# 将此作为 DocumentComplete 事件的第三个处理程序触发,因此它实际上并没有停止其他两个处理程序。
你知道如何修复它吗?
I have following code:
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Action1);
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Action2);
Works just fine.
But they seem to trigger every time any page is done downloading.
Though I want them to trigger only once for every page.
Say Action1 for Page1, Action2 for Page2 etc.
I tried to add an empty handler like this:
void StopDoingStuff(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Application.DoEvents();
}
But it seems that C# triggers this as a third handler for DocumentComplete event, so it does not actually stop other two.
Do you know how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要取消订阅事件,请使用以下语法:
这是 msdn 说明: http://msdn.microsoft.com/en-us/library/ms366768(v=VS.100).aspx
To unsubscribe from an event, use the following syntax:
Here's an msdn explanation: http://msdn.microsoft.com/en-us/library/ms366768(v=VS.100).aspx