Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to execute a method specific to a function in a different class from the main form class? (c#)
    primarykey
    data
    text
    <p>May be my lack of awareness of some key programming concept on polymorphism or interface inheritance etc. this should be easy. I'm a novice. </p> <p>I have a separate class in C# program called tts. Now I defined a function in it called speak. here is it:</p> <pre><code>class tts { public void speak() { Process process1 = new Process(); process1.StartInfo.FileName = "C:\\Program Files\\eSpeak\\command_line\\espeak.exe"; process1.StartInfo.Arguments = "hello"; process1.StartInfo.UseShellExecute = false; process1.StartInfo.CreateNoWindow = true; process1.Start(); //process1.Kill(); } } </code></pre> <p>When I call this function from main form under an event (<code>listBox1_SelectedIndexChange</code>), it runs fine. What this program does is read "hello" every time I scroll through my list box. But I want to kill process1 when I scroll to next item in listbox. when I implement the <code>process1.Kill()</code> (by uncommenting the kill method) in speak function, the program doesn't read "hello". What happens is that the process1 get killed immediately. So I would not implement method Kill() there under the speak function. But I want to kill process1 from main form when I change index of listbox (<code>listBox1_SelectedIndexChange</code>). Here is my main form code.</p> <pre><code> private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { tts obj = new tts(); obj.speak(); } </code></pre> <p>What I want to do is this:</p> <pre><code> private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { tts obj = new tts(); obj.speak(); process1.Kill(); } </code></pre> <p>which of course wont work since process1 is under the scope of function speak in class tts. how to execute <code>process1.Kill()</code> from main form?</p> <p>I would appreciate the basic code itself more than technical terms on what to do.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload