vb.net – 如何将参数传递给BackGroundWorker

前端之家收集整理的这篇文章主要介绍了vb.net – 如何将参数传递给BackGroundWorker前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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

如何将text2传递给vox.speak?

解决方法

在cmdSpeak_Click中,将text2作为参数传递给RunWorkerAsync

BackgroundWorker1.RunWorkerAsync(text2)

在BackgroundWorker1_DoWork中,检索参数的值

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

猜你在找的VB相关文章