How to pass arguments to a BackGroundWorker

爷,独闯天下 提交于 2019-12-20 02:31:05

问题


Imports SpeechLib

Public Class Form1
    Public vox = CreateObject("sapi.spvoice")

    Private Sub cmdSpeak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSpeak.Click
        Dim text2 As String = "Hello , This is a Text. Hello , This is a Text."
        BackgroundWorker1.RunWorkerAsync()
    End Sub

    Private Sub cmdPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPause.Click
        vox.pause()
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim SVEPhoneme As Integer = 64
        vox.EventInterests = SVEPhoneme
        vox.AlertBoundary = SVEPhoneme
    End Sub

    Private Sub cmdResume_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdResume.Click
        vox.resume()
    End Sub

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        vox.Speak(Text, SpeechVoiceSpeakFlags.SVSFlagsAsync)
    End Sub
End Class

How can I pass text2 to vox.speak?


回答1:


In cmdSpeak_Click, pass text2 as a parameter to RunWorkerAsync

BackgroundWorker1.RunWorkerAsync(text2)

In BackgroundWorker1_DoWork, retrieve the value of the parameter

vox.Speak(DirectCast(e.Argument, String), SpeechVoiceSpeakFlags.SVSFlagsAsync)


来源:https://stackoverflow.com/questions/4925997/how-to-pass-arguments-to-a-backgroundworker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!