I followed a speech recognition tutorial about opening and closing program. when I execute a command to open MS WORD it does fine but when I try to close the program I get an error message regarding the index was outside the bound of the array. It points to the Procs[0] as being out of bounds.
public static void killProg(string s)
{
System.Diagnostics.Process[] Procs = null;
try
{
Procs = Process.GetProcessesByName(s);
Process prog = Procs[0];
if (!prog.HasExited)
{
prog.Kill();
}
}
finally
{
if (Procs != null)
{
foreach (Process p in Procs)
{
p.Dispose();
}
}
}
Can anybody help? I'm very new to using C# and not sure what to do?