2017-06-11 74 views
0

我試圖通過子例程來通知一些我的程序的觀察者動畫轉換已完成。但它告訴我不能直接調用,我需要使用RaiseEvent。我嘗試添加處理程序,但仍然無效。我該怎麼辦?通過子程序提高事件

Utility.raiseEventTest(Me.TransitionCompletedEvent, Me, New Transition.Args()) 

https://prntscr.com/fiholb

Public Shared Sub raiseEventTest(Of T As System.EventArgs)(theEvent As EventHandler(Of T), sender As Object, args As T) 
     If theEvent Is Nothing Then 
      Return 
     End If 
     ' 
     For Each handler As EventHandler(Of T) In theEvent.GetInvocationList() 
      Try 
       Dim target As ISynchronizeInvoke = TryCast(handler.Target, ISynchronizeInvoke) 
       If target Is Nothing OrElse target.InvokeRequired = False Then 
        handler(sender, args) 
       Else 
        target.BeginInvoke(handler, New Object() {sender, args}) 
       End If 
      Catch generatedExceptionName As Exception 
      End Try 
     Next 
    End Sub 
+0

感謝您的快速回答。遺憾的是仍然如此:http://prntscr.com/fihqnd – Mava

回答

1

只需使用RaiseEvent的建議,沒有必要爲你使用這種類型的代碼...

變化:

Utility.raiseEventTest(Me.TransitionCompletedEvent, Me, New Transition.Args()) 

要:

RaiseEvent TransitionCompleted(Me, New Transition.Args()) 

所有訂戶都會收到通知並收到活動。

+0

這麼簡單。謝謝你,先生! – Mava