区分事件或编程调用的函数

时间:2013-11-27 20:41:50

标签: .net vb.net events

所以假设这个功能:

Private Function appendText() As Boolean Handles weComs.WriteChat
   if(Called by event)
     'do something
   else
     'do something

   Return Nothing
End Function

所以,就是这样,我想知道这个函数或方法是否有可能知道他是被事件调用还是被某个地方调用

1 个答案:

答案 0 :(得分:0)

最好的方法是使用发件人。但如果不这样做,请将其作为参数传递。

Private Function appendText_Event() As Boolean Handles weComs.WriteChat
    Return AppendText(True)
End Function

Private Function appendText() As Boolean
    Return AppendText(False)
End Function

Private Function AppendText(CalledByEvent as Boolean) As Boolean
   if(CalledByEvent)
     'do something
   else
     'do something

   Return Nothing
End Function