简体   繁体   English

如何取消绑定DocumentComplete处理程序?

[英]How do I unbind a DocumentComplete Handler?

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. 说第1页的Action1,第2页的Action2等。

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. 但似乎C#触发了它作为DocumentComplete事件的第三个处理程序,所以它实际上并没有阻止其他两个。

Do you know how to fix it? 你知道怎么解决吗?

To unsubscribe from an event, use the following syntax: 要取消订阅活动,请使用以下语法:

webBrowser1.DocumentCompleted -= Action2

Here's an msdn explanation: http://msdn.microsoft.com/en-us/library/ms366768(v=VS.100).aspx 这是一个msdn解释: http//msdn.microsoft.com/en-us/library/ms366768( v = VS.100) .aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM