This code is just designed to flicker.
If flickers due to
Hide/Show
and there is nothing you can do. This is not a real flicker though, this is normal rendering of a window when you hide and show it again. Try to run any normally behaving application and quickly hide and show it using the click on the system taskbar. Do you call it "flicker"? No. So, what your application does is not a flicker.
All you can do is re-design your application.
First, I cannot believe you really need to capture a screen periodically. Even if you need so many screen shots, I would assume you only need to make the screen short which are different, when something is changed on the screen. To trigger taking the screenshot, you need to use a global Window Hook. Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632589%28v=vs.85%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx[
^],
http://support.microsoft.com/kb/318804[
^].
Now, you cannot install the global Windows Hook in .NET code. According to Microsoft documentation, it should be a native DLL. It can communicate with your application. Some simple approach could be this: your application can run a polling thread taking the screenshot (by the way, since this moment, forget the idea of writing such application without extensive use of threading). The thread should be kept in the wait state by the call to a event wait handle
WaitOne
method, and a hook handler should simply set this handle (change it to its signaled state).
This part is not easy to implement at all. The detailed description of it would take a really big CodeProject article. You don't have much luck — it is not interesting enough to waste time on it. Your purpose is not clear, please see above.
Finally, let's address what you called "flicker".
Your application does not need UI. Even if by some reason it does, you can
minimize its window and never show during the acquisition. Show the window again only when a user restores it explicitly using Alt+TAB, Windows+Tab or taskbar. Yes,
as simple as that.
At the end, I would like to tell that I cannot believe making a sequence of screenshots using a timer or a periodic thread with Sleep may make any sense. You really need to share your ultimate goal and explain why would you need to do such a weird thing.
—SA