2015-04-03 41 views
0

使用InteropUserControl時出現問題:在InteropUserControl上,如果我同時引發2個事件,則Vb6應用程序將丟失其中一個事件。下面是重現行爲步驟:如果我在同一時間運行RaiseEvent,則會觸發一個事件

在VB.NET我創建了一個InteropUserControl:

Public Event TestEvent() 

Public Sub RaiseTestEvent() 
     BackgroundWorker1.RunWorkerAsync() 
End Sub 

Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted 
     RaiseEvent TestEvent() 
    End Sub 

VB6的,我創建了2 InteropUserControl並使用此代碼:

Private Sub Form_Load() 
Me.InteropUserControl1.RaiseTestEvent 
Me.InteropUserControl2.RaiseTestEvent 
End Sub 

Private Sub InteropUserControl1_TestEvent() 
MsgBox "InteropUserControl1 fired" 
End Sub 
Private Sub InteropUserControl2_TestEvent() 
MsgBox "InteropUserControl2 fired" 
End Sub 

我收到的只是一個事件被解僱,另一個失蹤。有沒有什麼好的解決方案不會錯過這些事件?

回答

0

你可以試試這個:

Public Async Function RaiseTestEvent() As Task 
    Await DoSomethingHere 
    RaiseEvent TestEvent 
End Function 

如果DoSomethingHere沒有異步,然後把上面一行Await Task.Run(Sub() DoSomethingHere)

相關問題