We have to use the Pinvoke
GetForegroundWindow method.
IntPtr hwnd = GetForegroundWindow();
uint pid;
GetWindowThreadProcessId(hwnd, out pid);
Process proc = Process.GetProcessById((int)pid);
once we get the processid only for that process i need to run automation element to find error window.and this method for finding active window run every 5 minutes via timer so that if my active window(Process) changes it will work(find error window) for that process.