|
-
Sep 26th, 2015, 12:04 PM
#1
Thread Starter
New Member
[RESOLVED] Thread, dispatcher - can't figure it out how to use it
Hi all
I'm learning how to start a new thread so my functions and GUI not freezing, but I don't understand how to use it.
I have made a small program that says what I put into the textbox, and while it's speaking, I want to be able to slide the slide bar or move the GUI around. Right now I can only do it when the speak stops.
Here is my code:
Code:
Imports System.Speech.Synthesis.SpeechSynthesizer
Public Class Form1
Dim sig As New Speech.Synthesis.SpeechSynthesizer()
Dim rate As Double
Dim StartTekst As String = "This is a test on how it sounds when the speech synthesizer says"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txtboxSigTekst.Text = StartTekst
End Sub
Private Sub btnSigTekst_Click(sender As Object, e As EventArgs) Handles btnSigTekst.Click
SigTekst()
End Sub
Private Sub SigTekst()
sig.Speak(txtboxSigTekst.Text)
End Sub
End Class
I have tried to insert a "dispatch" in the sub SigTekst (Dispatcher.BeginInvoke(New Action(AddressOf SigTekst))) but non of the different metodes I have tried, is working.
What am I doing wrong? Do I insert Dispatcher in the sub SigTekst or should it be in another place?
Can anyone help me to understand this? I think I better understand this if you could insert the code, as simple as possible, to start the sub in ad new thread.
-Salva
-
Sep 26th, 2015, 12:18 PM
#2
Re: Thread, dispatcher - can't figure it out how to use it
try this:
Code:
Imports System.Speech.Synthesis.SpeechSynthesizer
Public Class Form1
Dim sig As New Speech.Synthesis.SpeechSynthesizer()
Dim rate As Double
Dim StartTekst As String = "This is a test on how it sounds when the speech synthesizer says"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtboxSigTekst.Text = StartTekst
End Sub
Private Sub btnSigTekst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSigTekst.Click
Dim t As New Threading.Thread(AddressOf SigTekst)
t.Start(txtboxSigTekst.Text)
End Sub
Private Sub SigTekst(ByVal sayWhat As Object)
sig.Speak(sayWhat.ToString)
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 26th, 2015, 01:46 PM
#3
Re: Thread, dispatcher - can't figure it out how to use it
Why do you have two threads going on this topic - that stinks!
http://www.vbforums.com/showthread.p...-how-to-use-it
-
Sep 26th, 2015, 03:26 PM
#4
Re: Thread, dispatcher - can't figure it out how to use it
 Originally Posted by szlamany
I prefer my solution
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 26th, 2015, 03:54 PM
#5
Thread Starter
New Member
Re: Thread, dispatcher - can't figure it out how to use it
The other one is WPF code and not many people is active in WPF.
That why I created a form project
-
Sep 26th, 2015, 03:59 PM
#6
Thread Starter
New Member
Re: Thread, dispatcher - can't figure it out how to use it
YES God damed! Its working. finally. Spend two days on this 
Just had to remove the parameter in t.Start()
Thank you
-
Sep 26th, 2015, 04:33 PM
#7
Re: [RESOLVED] Thread, dispatcher - can't figure it out how to use it
Not passing the parameter that way causes cross thread calls that will affect your UI thread...
Code:
Private Sub btnSigTekst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSigTekst.Click
Dim t As New Threading.Thread(AddressOf SigTekst)
t.Start(txtboxSigTekst.Text) 'this is the parameter that is passed to SigTekst
End Sub
Code:
Private Sub SigTekst(ByVal sayWhat As Object) 'this is the parameter that is sent in t.Start
sig.Speak(sayWhat.ToString)
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 26th, 2015, 05:05 PM
#8
Re: [RESOLVED] Thread, dispatcher - can't figure it out how to use it
The TIMER in a regular WINFORM project is not the same as a WPF timer - which is the code I showed you - from a WPF program I have.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|