|
-
Dec 15th, 2008, 01:57 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] thread question
I have a custome user control that needs to use the voicesynthizer to speak the name of the contorl the user entered.
the problem that im running into is that the existing screen reading software reads a bunch of useless info at the exact same time( basically telling the user its a text box and they can type in it).
so i need to delay my program for a few seconds but i need to keep the rest of the program running and i can't pause the entire form
c# Code:
private void LBL_OT_Enter(object sender, EventArgs e)
{
Control C = new Control();
C = (Control)sender;
Thread newThread = new Thread(new ThreadStart(Work(LBL_Name.Text + " " + C.Tag)));
newThread.Start();
}
private void Work(string say)
{
SpeechSynthesizer Voice = new SpeechSynthesizer();
int waitTime = 1000;
Voice.SpeakAsyncCancelAll();
Thread.Sleep(waitTime);
Voice.SpeakAsync(say);
}
but im getting an syntax error saying that a method is expected but i thought that i provided Work with the apporiate string
what am i doing wrong
and am i going down the right path interms of delaying the code with out haulting the entire program?
-
Dec 15th, 2008, 02:55 PM
#2
Re: thread question
To pass a parameter to a method via a thread like this, I think you need to use a 'ParameterizedThreadstart' delegate instead of a ThreadStart.
You need to pass an object to the thread via the call to .start the thread, and then cast it to the type you want to use inside your method.
Something like this:
Code:
private void button1_Click(object sender, EventArgs e)
{
string textTosay = "abc";
Thread newThread = new Thread(new ParameterizedThreadStart(Work));
newThread.Start(textTosay);
}
private void Work(object state)
{
string say = state as string;
MessageBox.Show(say);
}
-
Dec 16th, 2008, 12:09 AM
#3
Thread Starter
Fanatic Member
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
|