开发者

How to pass arguments to a BackGroundWorker

开发者 https://www.devze.com 2023-02-08 21:39 出处:网络
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 cmdSpea
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?


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消