How can I control the order in which event handlers are fired?

后端 未结 5 1193
庸人自扰
庸人自扰 2021-01-03 23:09

Are event handlers fired in the order that they attached to the event? If not, can I enforce some kind of order onto the event handlers such that they are called in a specif

5条回答
  •  时光说笑
    2021-01-03 23:59

    I would recommend "wrapping it."

    Do something like this...

    MyObject.MyEvent += new MyEventHandler(Wrapper);
    
    public void Wrapper()
    {
        Method1();
        Method3();
        Method2();
    }
    

    That way you're still hooking the event but have complete control of what's called.

提交回复
热议问题