如何避免被處理兩次事件(如果是相同的處理?)避免重複的事件處理程序?
Module Module1
Sub Main()
Dim item As New Item
AddHandler item.TitleChanged, AddressOf Item_TitleChanged
AddHandler item.TitleChanged, AddressOf Item_TitleChanged
item.Title = "asdf"
Stop
End Sub
Private Sub Item_TitleChanged(sender As Object, e As EventArgs)
Console.WriteLine("Title changed!")
End Sub
End Module
Public Class Item
Private m_Title As String
Public Property Title() As String
Get
Return m_Title
End Get
Set(ByVal value As String)
m_Title = value
RaiseEvent TitleChanged(Me, EventArgs.Empty)
End Set
End Property
Public Event TitleChanged As EventHandler
End Class
輸出:
Title changed!
Title changed!
所需的輸出:
Title changed!
我希望事件管理器檢測到這個事件已經被這個處理器處理了,所以它不應該重新處理(或讀取)它。
這看起來像內存泄漏。 – 2015-06-24 16:53:24