使用InteropUserControl时出现问题:在InteropUserControl上,如果我同时引发2个事件,Vb6应用程序将缺少其中一个。以下是重现行为的步骤:
在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 :(得分:0)
你可以试试这个:
Public Async Function RaiseTestEvent() As Task
Await DoSomethingHere
RaiseEvent TestEvent
End Function
如果DoSomethingHere
不是异步,则将该行更改为Await Task.Run(Sub() DoSomethingHere)