<tfoot id='FSfao'></tfoot>
  • <small id='FSfao'></small><noframes id='FSfao'>

      <bdo id='FSfao'></bdo><ul id='FSfao'></ul>
    <legend id='FSfao'><style id='FSfao'><dir id='FSfao'><q id='FSfao'></q></dir></style></legend>
  • <i id='FSfao'><tr id='FSfao'><dt id='FSfao'><q id='FSfao'><span id='FSfao'><b id='FSfao'><form id='FSfao'><ins id='FSfao'></ins><ul id='FSfao'></ul><sub id='FSfao'></sub></form><legend id='FSfao'></legend><bdo id='FSfao'><pre id='FSfao'><center id='FSfao'></center></pre></bdo></b><th id='FSfao'></th></span></q></dt></tr></i><div id='FSfao'><tfoot id='FSfao'></tfoot><dl id='FSfao'><fieldset id='FSfao'></fieldset></dl></div>

        我如何知道 .net 事件是否已被处理?

        How can I know if a .net event is already handled?(我如何知道 .net 事件是否已被处理?)
        <tfoot id='Dqg0W'></tfoot>
        1. <i id='Dqg0W'><tr id='Dqg0W'><dt id='Dqg0W'><q id='Dqg0W'><span id='Dqg0W'><b id='Dqg0W'><form id='Dqg0W'><ins id='Dqg0W'></ins><ul id='Dqg0W'></ul><sub id='Dqg0W'></sub></form><legend id='Dqg0W'></legend><bdo id='Dqg0W'><pre id='Dqg0W'><center id='Dqg0W'></center></pre></bdo></b><th id='Dqg0W'></th></span></q></dt></tr></i><div id='Dqg0W'><tfoot id='Dqg0W'></tfoot><dl id='Dqg0W'><fieldset id='Dqg0W'></fieldset></dl></div>

          • <legend id='Dqg0W'><style id='Dqg0W'><dir id='Dqg0W'><q id='Dqg0W'></q></dir></style></legend>

                <bdo id='Dqg0W'></bdo><ul id='Dqg0W'></ul>

                    <tbody id='Dqg0W'></tbody>

                  <small id='Dqg0W'></small><noframes id='Dqg0W'>

                1. 本文介绍了我如何知道 .net 事件是否已被处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我编写了一些代码来处理事件,如下所示:

                  I've written some code to handle an event as follows:

                  AddHandler myObject.myEvent, AddressOf myFunction
                  

                  一开始似乎一切正常,但是当我运行调试器时,我发现 myFunction 经常会在每次 myObject.myEvent 触发时运行几次.我发现我允许代码添加事件处理程序多次运行,导致了这种行为.

                  It seemed that everything was working at first, but when I ran the debugger, I discovered that oftentimes, myFunction would run several times each time myObject.myEvent fired. I figured out that I had allowed the code to add the event handler to run more than once, resulting in this behavior.

                  有没有办法让我做这样的事情?

                  Is there a way I can do something like this?

                  If myObject.myEvent is not handled Then
                    AddHandler myObject.myEvent, AddressOf myFunction
                  End If
                  

                  推荐答案

                  假设发布事件的不是你的代码,你不能.这个想法是订阅者彼此隔离 - 您无法了解其他事件订阅者,自己引发事件等.

                  Assuming it's not your code that's publishing the event, you can't. The idea is that subscribers are isolated from each other - you can't find out about other event subscribers, raise the event yourself etc.

                  如果问题是多次添加自己的处理程序,您应该能够通过跟踪是否添加了处理程序来自己解决这个问题.Steven 在添加之前删除处理程序的想法是一个有趣的解决方法:尝试删除处理程序是有效的,即使它没有被订阅.但是,我认为这是您的应用程序不知道它应该做什么的解决方法.这是一个非常快速的短期解决方案,但我会担心将其长期保留.

                  If the problem is that you're adding your own handler multiple times, you should be able to fix that yourself by keeping track of whether you have added a handler. Steven's idea of removing the handler before adding it is an interesting workaround: it's valid to attempt to remove a handler even when it isn't subscribed. However, I'd regard this as a workaround to your app not really knowing what it should be doing. It's a very quick short-term fix, but I'd be worried about leaving it in for the longer term.

                  这篇关于我如何知道 .net 事件是否已被处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  IBM.Data.DB2.Core connection problems(IBM.Data.DB2.Core 连接问题)
                  Datetime field overflow with IBM Data Server Client v9.7fp5(IBM Data Server Client v9.7fp5 的日期时间字段溢出)
                  Using entity Framework with .NET Core and DB2(将实体框架与 .NET Core 和 DB2 结合使用)
                  IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                  .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                  Cannot connect to DB2: IBM.Data.DB2.Core version 3.1.0.400 on Azure Function(无法连接到 DB2:Azure 函数上的 IBM.Data.DB2.Core 版本 3.1.0.400)
                2. <tfoot id='9Xs0r'></tfoot>
                  1. <small id='9Xs0r'></small><noframes id='9Xs0r'>

                      <bdo id='9Xs0r'></bdo><ul id='9Xs0r'></ul>

                        <tbody id='9Xs0r'></tbody>

                        <i id='9Xs0r'><tr id='9Xs0r'><dt id='9Xs0r'><q id='9Xs0r'><span id='9Xs0r'><b id='9Xs0r'><form id='9Xs0r'><ins id='9Xs0r'></ins><ul id='9Xs0r'></ul><sub id='9Xs0r'></sub></form><legend id='9Xs0r'></legend><bdo id='9Xs0r'><pre id='9Xs0r'><center id='9Xs0r'></center></pre></bdo></b><th id='9Xs0r'></th></span></q></dt></tr></i><div id='9Xs0r'><tfoot id='9Xs0r'></tfoot><dl id='9Xs0r'><fieldset id='9Xs0r'></fieldset></dl></div>

                            <legend id='9Xs0r'><style id='9Xs0r'><dir id='9Xs0r'><q id='9Xs0r'></q></dir></style></legend>