Hi @Peter Volz ,
Please check if the following code helps.
Public Class MainForm
Private WithEvents MyOOSDK As Blah
Public Sub New()
InitializeComponent()
MyOOSDK = New Blah()
End Sub
' Event handler for the SDK component's events
Private Sub MyOOSDK_EventOccurred(sender As Object, e As EventArgs) Handles MyOOSDK.EventOccurred
If Me.InvokeRequired Then
Me.Invoke(Sub() MyOOSDK_EventOccurred(sender, e))
Else
' Handle the event on the UI thread
End If
End Sub
' Method to start a new thread
Private Sub StartThread()
Dim myThread As New Thread(AddressOf YourThreadMethod)
myThread.Start()
myThread.Join() ' Wait for the thread to finish
End Sub
End Class
Create a base form (let's say BaseForm
) that inherits from MainForm
. This base form will contain the MyOOSDK
object and its associated event handlers.
Public Class BaseForm
Inherits MainForm
' Thread checker method for UI thread
Private Sub CheckUIThread()
If Not Me.InvokeRequired Then
' Code that should run on the UI thread
Else
Throw New InvalidOperationException("Method must be called on the UI thread.")
End If
End Sub
End Class
Then create other forms that inherit from BaseForm. These forms will have access to the MyOOSDK object and its event handlers as well.
Public Class OtherForm
Inherits BaseForm
' You can use MyOOSDK and its events here
Private Sub SomeMethod()
CheckUIThread() ' Ensure we are on the UI thread
' Code that interacts with UI elements
End Sub
End Class
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.