There are a lot of ways to do this. You could use a BackgroundWorker
, start a plain Thread
, use the ThreadPool
, etc. Here is an example using the threadpool.
You have to rewrite your method to match the WaitCallback
signature (which takes a plain Object
):
'be sure to add
Imports System.Threading.ThreadPool
'...
'need an object type to pass
Private Class AudioBoxArgs
Public Message As String
End Class
Private Sub audioBox(ByVal state As Object)
cls_utilidades.Audio_Box(DirectCast(state, AudioBoxArgs).Message)
End Sub
then in your click handler :
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles Button1.Click
Dim someMessage As New AudioBoxArgs()
someMessage.Message = "someMessage"
QueueUserWorkItem(AddressOf audioBox, someMessage)
End Sub
As with all asynchronous code, you should make sure that cls_utilidades.Audio_Box()
is a safe method to call from a separate thread. If you're not yet familiar with thread safety it's something you will have to start learning.