简体   繁体   中英

C#: How do I execute a method on a property that has an attached event handler (without a stack overflow)

Setup: I have attached an event handler on the WebBrowser control something like this...

ChatInputElement.AttachEventHandler("onpropertychange", OnInputChange);

That part works perfect... But the site I'm messing with inputs URLEncoded information into the Input area sometime, which lacks a good human readable experience.

So I was trying to take advantage of the "onpropertychange" event, to fire a method that would URLDecode the data in the input box. Unfortunately this causes a Stack Overflow due to the "onpropertychange" event getting fired when I decode the URL...

Question: How can I accomplish URLDecoding the data in the input box, without causing a Stack Overflow? Is there a way to detect URLEncoded material, because the input box does contain data that doesn't need to be decoded at times.

您可以在处理程序中设置一个类级别的标志,如果设置了该标志,则退出处理程序。

Store the result for comparison in subsequent handler-invocations:

One way to prevent the loop is to store your decoded URL in a field variable before setting the property. Then, set the property. On the second invocation of the event handler, compare the stored field with the current value of the property. If it's the same, you know that you already URLDecoded it, and you exit the event handler without modifying the property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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