hello, in the following code
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// check if any kinect is available
if (Sensors.Count == 0)
{
MessageBox.Show("no sensor is available for listening !!");
Application.Current.Shutdown();
}
///
///
PromptBuilder pb1 = new PromptBuilder();
pb1.AppendText("HELLO", System.Speech.Synthesis.PromptVolume.Loud);
this.speaker(pb1);
}
the last three lines are executed even though the ' if ' condition is satisfied! can anyone explain me why ? i think the application should shutdown .


VulpesRank #55 · 29.2K reputationPosted Jan 16, 2015, 2:04 AM EST
I tend to prefer this to using 'else' if there would be a lot of code to indent as I like to keep indentation to a minimum. However, with just 3 lines it's a matter of taste which you use.
VulpesRank #55 · 29.2K reputationPosted Jan 17, 2015, 3:18 AM EST
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Jan 15, 2015, 8:30 PM EST
Hi sanju singh,
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// check if any kinect is available
if (Sensors.Count == 0)
{
MessageBox.Show("no sensor is available for listening !!");
Application.Current.Shutdown();
}
///
///
else{
PromptBuilder pb1 = new PromptBuilder();
pb1.AppendText("HELLO", System.Speech.Synthesis.PromptVolume.Loud);
this.speaker(pb1);
}
}
Now it will not execute actually you did not put those condition inside else block so whenever if condition over after that last three lines will execute. The execution process is top to Bottom so after finishing the if block execution those three line will execute
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Jan 16, 2015, 8:24 PM EST
Application.Exit();
and, if that doesn't work:
Environment.Exit(1);
Before calling either of these close all connections manually and releasing unmanaged resources by calling Dispose() on any object still in scope which implements IDisposable.
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Jan 16, 2015, 10:44 PM EST
Sanju SinghRank #6,374 · 268 reputationPosted Jan 16, 2015, 5:15 PM EST
Sanju SinghRank #6,374 · 268 reputationPosted Jan 16, 2015, 5:16 PM EST
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Jan 16, 2015, 6:22 PM EST
break;
Sanju SinghRank #6,374 · 268 reputationPosted Jan 16, 2015, 7:48 PM EST
Sanju SinghRank #6,374 · 268 reputationPosted Jan 16, 2015, 7:51 PM EST
Sanju SinghRank #6,374 · 268 reputationPosted Jan 16, 2015, 10:42 PM EST
Sanju SinghRank #6,374 · 268 reputationPosted Jan 18, 2015, 5:01 PM EST
Sanju SinghRank #6,374 · 268 reputationPosted Jan 18, 2015, 5:11 PM EST