我有一个显示消息框的表单,同时启动了一个说出相同消息的新线程。
我想要实现的是在我单击OK
消息框上的按钮后立即停止线程说出消息。
我尝试在单击OK
消息框后立即使用 abort 命令终止线程,但即使消息框消失,SPEAK 进程仍会继续说出整个消息。
我假设新线程正在被 abort 命令杀死,但说话过程可能正在使用某个玩家说出消息并且该玩家没有被停止。任何帮助将不胜感激。
这是代码:
Imports SpeechLib
Public Class Form1
Public voice As SpVoice = New SpVoice()
Public speak As Boolean = True
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
Dim t1 As New Threading.Thread(AddressOf THREAD)
t1.IsBackground = True
t1.Start()
MessageBox.Show("Data has not been saved yet. Are you sure you want to quit with out saving the chandes?")
t1.Abort()
End Sub
Public Sub THREAD()
If (speak = True) Then
voice.Speak("Data has not been saved yet. Are you sure you want to quit with out saving the chandes?")
End If
End Sub
End Class