假設我的程式碼是this.FormClosing += new FormClosingEventHandler (this.freeThread);那我要如何知道 this.FormClosing 已經綁定了 this.freeThread 這個事件呢?
因為上面那段我我不想要重複綁定事件,或是說要如何避免呢?

解决方案 »

  1.   

    this.FormClosing
    看这个是不是为空了
      

  2.   

    看看这个帖子,需要用到:GetInvocationListhttp://topic.csdn.net/u/20100419/14/c0b13122-95af-409b-b947-611c7649268e.html
      

  3.   


                    Delegate[] allDlg = new Delegate[this.GetInvocationList().GetLength(0)];
                    this.GetInvocationList().CopyTo(allDlg, 0);                foreach (Delegate dlg in allDlg)
                    {
                        if (dlg.Method.Name == "freeThread")
                        {
                            //不在绑定
                        }
                        else
                        {
                            //绑定
                            this.FormClosing += new FormClosingEventHandler (freeThread);
                            MessageBox.Show("绑定成功");
                        }
                    }
      

  4.   


    謝謝你,這就是我要的,不過 c# 做起來有點麻煩,不像 AS3 會在每個物件都有個 hasEventListener 方法可以直接傳回結果。