为什么 CloseMainWindow() 关闭我的命令屏幕而不是在 C# 中激活 window?
Why CloseMainWindow() close my command screen instead of the activate window in C#?
我想使用 C# 语音识别程序打开和关闭文件,但是当我说关闭时,我的程序关闭了我的控制台,而不是我在启动 .wmv 文件时使用的程序,如 vlc。你能解释一下为什么会这样吗?
这是我的 SpeechRecognition 函数的代码:
private static Process lastStartedProcess;
private static void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)//Méthode qui s'active lorsque l'ordi reconnait la phrase
{
if (e.Result.Text == "test")//e.Result contains the recognized text
{
Console.WriteLine("The test was successful");
}
else if (e.Result.Text == "exit")
{
_completed.Set(); //Calling the Set method will end the program
}
else if (e.Result.Text == " music")
{
lastStartedProcess = Process.Start(@"C:\Users\Public\Music\Sample Music\");
}
else if (e.Result.Text == " Pictures")
{
lastStartedProcess = Process.Start(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");//En appelant music, j'affecte le process music a ma variable process
}
else if (e.Result.Text == " Movies")
{
lastStartedProcess = Process.Start(@"C:\Users\Public\Videos\Sample Videos\Wildlife.wmv");
}
else if (e.Result.Text == "Close")
{
if (lastStartedProcess != null)
{
lastStartedProcess.CloseMainWindow();//Ici je ferme le process qui est present dans ma variable process en appelant CloseMainWindow
lastStartedProcess.WaitForExit();
}
}
}
Process.GetCurrentProcess() 将获取您的语音识别过程。您需要引用从 Process.Start 调用返回的 Process 实例。
我想使用 C# 语音识别程序打开和关闭文件,但是当我说关闭时,我的程序关闭了我的控制台,而不是我在启动 .wmv 文件时使用的程序,如 vlc。你能解释一下为什么会这样吗?
这是我的 SpeechRecognition 函数的代码:
private static Process lastStartedProcess;
private static void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)//Méthode qui s'active lorsque l'ordi reconnait la phrase
{
if (e.Result.Text == "test")//e.Result contains the recognized text
{
Console.WriteLine("The test was successful");
}
else if (e.Result.Text == "exit")
{
_completed.Set(); //Calling the Set method will end the program
}
else if (e.Result.Text == " music")
{
lastStartedProcess = Process.Start(@"C:\Users\Public\Music\Sample Music\");
}
else if (e.Result.Text == " Pictures")
{
lastStartedProcess = Process.Start(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");//En appelant music, j'affecte le process music a ma variable process
}
else if (e.Result.Text == " Movies")
{
lastStartedProcess = Process.Start(@"C:\Users\Public\Videos\Sample Videos\Wildlife.wmv");
}
else if (e.Result.Text == "Close")
{
if (lastStartedProcess != null)
{
lastStartedProcess.CloseMainWindow();//Ici je ferme le process qui est present dans ma variable process en appelant CloseMainWindow
lastStartedProcess.WaitForExit();
}
}
}
Process.GetCurrentProcess() 将获取您的语音识别过程。您需要引用从 Process.Start 调用返回的 Process 实例。