Results 1 to 3 of 3

Thread: [RESOLVED] thread question

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Resolved [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:
    1. private void LBL_OT_Enter(object sender, EventArgs e)
    2.         {
    3.             Control C = new Control();
    4.             C = (Control)sender;
    5.  
    6.  
    7.             Thread newThread = new Thread(new ThreadStart(Work(LBL_Name.Text + "  " + C.Tag)));
    8.        
    9.             newThread.Start();
    10.         }
    11.  
    12.  
    13.         private void Work(string say)
    14.         {
    15.             SpeechSynthesizer Voice = new SpeechSynthesizer();
    16.             int waitTime = 1000;
    17.             Voice.SpeakAsyncCancelAll();
    18.             Thread.Sleep(waitTime);
    19.             Voice.SpeakAsync(say);
    20.         }

    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?

  2. #2
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    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);
            }
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  3. #3

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: thread question

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width