[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);
private void Kill(Application theApp)
{
if (theApp == null)
{
return;
}
int iId = 0;
IntPtr intptr = new IntPtr(theApp.Hwnd);
System.Diagnostics.Process p = null;
try
{
GetWindowThreadProcessId(intptr, out iId);
p = System.Diagnostics.Process.GetProcessById(iId);
if (p != null)
{
p.Kill();
p.Dispose();
}
}
catch (Exception e)
{
throw e;
}
}