A puzzling problem with graphics painting and Alt-Tab

  • Thread starter Thread starter Tom Dacon
  • Start date Start date
T

Tom Dacon

I've got a little windows forms program that updates its graphics regularly
on a timer. It doesn't depend on the Paint event, although it responds to it
when one arrives. When I press the Alt-Tab key combination, the displayed
graphics no longer gets updated so the display on the form appears to
freeze. I've traced the code with trace statements: the timer continues to
pop on schedule, the paint logic is definitely being executed, no exceptions
are being silently swallowed, but the graphics is never sent to the screen.
A google groups search on the MS .Net forums didn't turn up any information.
Any ideas?

Thanks,
Tom Dacon
Dacon Software Consulting
 
Hi Tom,

I did a quick test using the following code snippet. When running it on my
Windows XP system, I pressed alt-tab and hold down the alt key to keep the
switch window visible, the Timer event handler still updated the screen
properly.
<code>
Color[] clr = { Color.Red , Color.Pink,Color.Yellow,
Color.Green,Color.Purple, Color.Blue};
int idx = 0;
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
using (Graphics graphics = panel1.CreateGraphics())
{
Color c = clr [ idx++ % clr.Length ];
using (Brush brush = new SolidBrush( c ))
{
graphics.FillRectangle ( brush, panel1.ClientRectangle );
}
}
}
</code>

Could you make a simple program to reproduce this problem, so we can look
into it further.

Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Thanks for the speedy response. This code snippet works for me too - I'm
going to incrementally add the features of my application until it breaks or
I figure out what's going on. So far I've added a transparent background on
the form and double-buffering for the painting and it continues to work.

Film at 11...

Tom
 
Thanks for the code snippet. I started with the code you supplied in the
code snippet below, built it into a windows app that refused to fail during
the Alt-Tab sequence, and then incrementally added code to it from my own
(failing) application until it fails too.

The problem happens when you: (1) in the designer, set the form's
TransparencyKey to anything besides the default and set the form's border
style to Sizable (the default), and (2) in the Form_Load event, set the
form's FormBorderStyle to anything besides what it was set to in the
designer. In my case, it was set to FormBorderStyle.None in the form's load
event. Both these things need to happen for it to fail.

Once both those things have been done, my test app fails during the Alt-Tab
sequence when you hold down the Alt key and tap the Tab key until the test
app is selected in the Alt-Tab UI. When it becomes selected, the display
freezes, retaining the visuals that were painted during the update just
before it was selected.

I'm sending by offline channel a Zip file that contains the project.

Now all I need to do is figure out how to change my app so that I don't need
to change the FormBorderStyle in the Load event...

Thanks,
Tom Dacon
Dacon Software Consulting
 
Hi Tom,

Thanks for your sample and the detail information.

I followed the instructions in the readme.txt to test your sample program
on my machine and another test machine, one machine is XP sp1 another is
windows 2003 both system have VS.NET 2003 installed. However the test
sample works fine on both systems. Is this issue only happened on certain
systems?
If so, you may check if there are some global windows hooks installed on
your system. We don't have a good way to check if there is a global hook ,
but you may check the loaded modules of this program,

You may use the utility ListDLLs from SysInternal to get a list of the
loaded modules and check if there is any strange modules loaded.
You may download ListDLLs from :
http://www.sysinternals.com/ntw2k/freeware/listdlls.shtml
Here is a list of loaded modules when running the test program on my system:
Alt-Tab and Graphics, POC.exe pid: 3040
Command line: "Alt-Tab and Graphics, POC.exe"
Version Path
1.00.1663.19566 E:\Customers_code\Alt-Tab and Graphics\bin\Debug\Alt-Tab
and Graphics, POC.exe
5.01.2600.1217 D:\WINDOWS\System32\ntdll.dll
2.00.40607.0016 D:\WINDOWS\system32\mscoree.dll
5.01.2600.1106 D:\WINDOWS\system32\KERNEL32.dll
5.01.2600.1106 D:\WINDOWS\system32\ADVAPI32.dll
5.01.2600.1361 D:\WINDOWS\system32\RPCRT4.dll
6.00.2800.1400 D:\WINDOWS\system32\SHLWAPI.dll
7.00.2600.1106 D:\WINDOWS\system32\msvcrt.dll
5.01.2600.1346 D:\WINDOWS\system32\GDI32.dll
5.01.2600.1255 D:\WINDOWS\system32\USER32.dll
5.01.2600.1106 D:\WINDOWS\System32\IMM32.DLL
5.01.2600.0000 D:\WINDOWS\System32\LPK.DLL
1.409.2600.1106 D:\WINDOWS\System32\USP10.dll
1.01.4322.2030 D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorwks.dll
7.10.3052.0004 D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\MSVCR71.dll
1.01.4322.2030 D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\fusion.dll
5.01.2600.1362 D:\WINDOWS\system32\ole32.dll
6.00.2800.1233 D:\WINDOWS\system32\SHELL32.dll
6.00.2800.1106
D:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0
.10.0_x-ww_f7fb5805\comctl32.dll
5.82.2800.1106 D:\WINDOWS\system32\comctl32.dll
1.01.4322.2030 d:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll
6.00.2800.1405 D:\WINDOWS\system32\WININET.dll
5.131.2600.1123 D:\WINDOWS\system32\CRYPT32.dll
5.01.2600.1362 D:\WINDOWS\system32\MSASN1.dll
3.50.5016.0000 D:\WINDOWS\system32\OLEAUT32.dll
5.01.2600.1106 D:\WINDOWS\System32\Secur32.dll

d:\windows\assembly\nativeimages1_v1.1.4322\mscorlib\1.0.5000.0__b77a5c56193
4e089_eb123773\mscorlib.dll
1.01.4322.0573 D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorsn.dll
6.00.2800.1106 D:\WINDOWS\System32\uxtheme.dll
5.01.2600.1106 D:\WINDOWS\System32\MSCTF.dll
1.01.4322.2030
d:\windows\assembly\gac\system.windows.forms\1.0.5000.0__b77a5c561934e089\sy
stem.windows.forms.dll

d:\windows\assembly\nativeimages1_v1.1.4322\system.windows.forms\1.0.5000.0_
_b77a5c561934e089_21710e7e\system.windows.forms.dll
1.01.4322.2030
d:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll

d:\windows\assembly\nativeimages1_v1.1.4322\system\1.0.5000.0__b77a5c561934e
089_7259b343\system.dll
1.01.4322.2030 D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\MSCORJIT.DLL
7.10.3052.0004
D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\diasymreader.dll
1.01.4322.2030
d:\windows\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.d
rawing.dll

d:\windows\assembly\nativeimages1_v1.1.4322\system.drawing\1.0.5000.0__b03f5
f7f11d50a3a_e65358c8\system.drawing.dll
1.01.4322.2030
d:\windows\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.d
ll

d:\windows\assembly\nativeimages1_v1.1.4322\system.xml\1.0.5000.0__b77a5c561
934e089_a5c4548e\system.xml.dll
5.01.2600.1106 D:\WINDOWS\System32\msctfime.ime
5.01.3101.0000
D:\WINDOWS\WinSxS\x86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.10.0_x-
ww_712befd8\gdiplus.dll
5.01.2600.1106 D:\WINDOWS\System32\Msimtf.dll

If your list is different to the list above, you may try temporary remove
the different dll ,then reboot the system and try again to see if the
problem still persists.

Please feel free to let me know if you have any questions when analyzing
the module list.

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
OK, I think I've got it.

I have the Windows XP PowerToys installed on the two machines I've run the
app on. One of the power toys is the Task Switcher replacement for the
normal Windows XP Alt-Tab dialog. This replacement task switcher grabs and
displays on its dialog form a thumbnail of each application's screen as it
cycles through the applications. When I removed that power toy, rebooted,
and ran the test application, it worked just file (didn't freeze as the
Alt-Tab dialog selected it). When I reinstalled it, the problem came back.

So now it's probably a little tough to figure out where to point the
fingerbone of blame. Is is the replacement task switcher? Is it some
vulnerability in the .Net Windows Forms runtime? Is it me for tinkering with
the form's border style so early in the form startup process? I noticed that
the Load event happens before the first Layout event (the one with the null
arguments), so maybe it's a little too soon for me to be doing what I'm
doing.

Whattaya think?

Tom Dacon

"Ying-Shen Yu[MSFT]" said:
Hi Tom,

Thanks for your sample and the detail information.

I followed the instructions in the readme.txt to test your sample program
on my machine and another test machine, one machine is XP sp1 another is
windows 2003 both system have VS.NET 2003 installed. However the test
sample works fine on both systems. Is this issue only happened on certain
systems?
If so, you may check if there are some global windows hooks installed on
your system. We don't have a good way to check if there is a global hook ,
but you may check the loaded modules of this program,

You may use the utility ListDLLs from SysInternal to get a list of the
loaded modules and check if there is any strange modules loaded.
You may download ListDLLs from :
http://www.sysinternals.com/ntw2k/freeware/listdlls.shtml
Here is a list of loaded modules when running the test program on my system:
Alt-Tab and Graphics, POC.exe pid: 3040
Command line: "Alt-Tab and Graphics, POC.exe"
Version Path
1.00.1663.19566 E:\Customers_code\Alt-Tab and Graphics\bin\Debug\Alt-Tab
and Graphics, POC.exe
5.01.2600.1217 D:\WINDOWS\System32\ntdll.dll
2.00.40607.0016 D:\WINDOWS\system32\mscoree.dll
5.01.2600.1106 D:\WINDOWS\system32\KERNEL32.dll
5.01.2600.1106 D:\WINDOWS\system32\ADVAPI32.dll
5.01.2600.1361 D:\WINDOWS\system32\RPCRT4.dll
6.00.2800.1400 D:\WINDOWS\system32\SHLWAPI.dll
7.00.2600.1106 D:\WINDOWS\system32\msvcrt.dll
5.01.2600.1346 D:\WINDOWS\system32\GDI32.dll
5.01.2600.1255 D:\WINDOWS\system32\USER32.dll
5.01.2600.1106 D:\WINDOWS\System32\IMM32.DLL
5.01.2600.0000 D:\WINDOWS\System32\LPK.DLL
1.409.2600.1106 D:\WINDOWS\System32\USP10.dll
1.01.4322.2030 D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorwks.dll
7.10.3052.0004 D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\MSVCR71.dll
1.01.4322.2030 D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\fusion.dll
5.01.2600.1362 D:\WINDOWS\system32\ole32.dll
6.00.2800.1233 D:\WINDOWS\system32\SHELL32.dll
6.00.2800.1106
D:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0
10.0_x-ww_f7fb5805\comctl32.dll
5.82.2800.1106 D:\WINDOWS\system32\comctl32.dll
1.01.4322.2030 d:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll
6.00.2800.1405 D:\WINDOWS\system32\WININET.dll
5.131.2600.1123 D:\WINDOWS\system32\CRYPT32.dll
5.01.2600.1362 D:\WINDOWS\system32\MSASN1.dll
3.50.5016.0000 D:\WINDOWS\system32\OLEAUT32.dll
5.01.2600.1106 D:\WINDOWS\System32\Secur32.dll

d:\windows\assembly\nativeimages1_v1.1.4322\mscorlib\1.0.5000.0__b77a5c56193
4e089_eb123773\mscorlib.dll
1.01.4322.0573 D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorsn.dll
6.00.2800.1106 D:\WINDOWS\System32\uxtheme.dll
5.01.2600.1106 D:\WINDOWS\System32\MSCTF.dll
1.01.4322.2030
d:\windows\assembly\gac\system.windows.forms\1.0.5000.0__b77a5c561934e089\sy
stem.windows.forms.dll
d:\windows\assembly\nativeimages1_v1.1.4322\system.windows.forms\1.0.5000.0_
_b77a5c561934e089_21710e7e\system.windows.forms.dll
1.01.4322.2030
d:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll
d:\windows\assembly\nativeimages1_v1.1.4322\system\1.0.5000.0__b77a5c561934e
089_7259b343\system.dll
1.01.4322.2030
D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\MSCORJIT.DLL
7.10.3052.0004
D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\diasymreader.dll
1.01.4322.2030
d:\windows\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.d
rawing.dll
d:\windows\assembly\nativeimages1_v1.1.4322\system.drawing\1.0.5000.0__b03f5
f7f11d50a3a_e65358c8\system.drawing.dll
1.01.4322.2030
d:\windows\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.d
d:\windows\assembly\nativeimages1_v1.1.4322\system.xml\1.0.5000.0__b77a5c561
934e089_a5c4548e\system.xml.dll
5.01.2600.1106 D:\WINDOWS\System32\msctfime.ime
5.01.3101.0000
D:\WINDOWS\WinSxS\x86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.10.0_x-
ww_712befd8\gdiplus.dll
5.01.2600.1106 D:\WINDOWS\System32\Msimtf.dll

If your list is different to the list above, you may try temporary remove
the different dll ,then reboot the system and try again to see if the
problem still persists.

Please feel free to let me know if you have any questions when analyzing
the module list.

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Hi Tom,

I installed the Task Switcher on my system and reproduced this issue,
After some investigation, it seems this issue is related to an API call
PrintWindow (TaskSwitcher uses it to capture the window thumbnail). I tried
to reproduce this issue using native win32 application but failed, so I
guess it is an issue in winform or gdi+, I'll forward this issue to the
Dev team to let them do further investigation.

However since PrintWindow is not used frequently, maybe the easiest
workaround is do not use the Task Switcher.

If this workaround is not suitable for your scenario, please feel free to
reply this thread to let me know.

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Thanks for researching that. It's nice to have a good idea about what's
going on with what was otherwise a pretty baffling problem.

As an old VB6/5/4/3/2/1 programmer, I've always been accustomed to doing
application-specific form initialization in the form's Load event, and in
those environments it worked just fine for me. Things are a lot different in
the .Net world and I can see that I need to question those old assumptions.
The best way to do these things now, apparently, is to put the
initialization code in the constructor, after the InitializeComponent()
call.

Since my last post, I took the initialization code that was in the form's
load event and moved it to an initialization routine that I'm now calling
from the constructor after InitializeComponent() has done its thing. Since
I've done that, the problem no longer occurs, even with the replacement
TaskSwitcher running. If I do anything at all in the Load event handler that
affects the underlying Win32 window, I can make the problem recur. This can
be a change in the form's dimensions, a change to the FormBorderStyle, or
possibly any one of a large range of other actions.

So I'm good to go with this solution, on the two applications in which I was
having the problem, and it's a good thing that I have a solution, since I
can't control whether the replacement TaskSwitcher is installed on the
machines these applications might be installed on. In addition, I've learned
a valuable lesson about the .Net framework as well.

Thanks for your help,
Tom Dacon
Dacon Software Consulting
 
Back
Top