I have the following two line code which will bring the respective window to the front that will help me take screenshots automatically. But the problem is that, sometimes, it works like a charm and sometimes it doesn’t. And when I say it doesn’t work, I don’t mean that it is failing with any error message or warnings. Nothing happens. Just the code runs and the windows doesn’t come to the front.
I would like to know if there is any hidden prerequisites for this snippet to run successfully? Should the window in question should be in any state before I run this code to bring that window upfront?
Here is the code:
Source: Stack Overflow