Issue with SetForegroundWindow in .NET

c#, pinvoke, visual-studio-2012, winapi

Solution

David was right and led me to the right direction . Followed the code project article which says "The system automatically enables calls to SetForegroundWindow if the user presses the ALT key or takes some action that causes the system itself to change the foreground window"

How to bring window to top with SetForegroundWindow()

Problem

I'm using SetForegroundWindow API in .NET using PInvoke. When I use the API while debugging in Visual Studio its works perfectly. But it doesn't work always when the application is running normally. I put some logs just before a call to SetForegroundWindow and its confirmed that the API is getting called but doesn't take effect at times. I have also seen a couple of posts regarding this issue but I want to know why is it failing. The links of the post are a follows: - Win32 SetForegroundWindow unreliable - SetForegroundWindow only working while visual studio is open

Original source

Related problems