Call this function to close the app:
System.Diagnostics.Process.GetCurrentProcess().CloseMainWindow();
View the discussion thread.