Error while trying to clear clipboard in Windows 7 and C# 3.5

Posted 01 October 2010 - 04:01 PM

Hi
I'm having a stupid problem trying to clear the clipboard in C# 3.5 on Windows 7 - every time I do this the explorer crashes.
At first I didn't know my application is causing this so I spent about a week and a half trying to find the problem.
In the end, a guy from MS forum "remembered" that Windows 7 has a bug that causes explorer.exe to crash every time you try to manipulate the clipboard :|. Apparently Firefox had the same problem a while ago.
At first I tried the simple way: Clipboard.Clear();
Since this was causing the crash I decided to add a control var so that I can check if the clipboard is empty or not:

Re: Error while trying to clear clipboard in Windows 7 and C# 3.5

Posted 02 October 2010 - 03:12 AM

I don't know what to say. I tested my app on 4 PCs all running Win7 Pro (2 with x64 and 2 with x86). Also tested on Windows Vista and XP in virtual box and had no problem there. Only on Win7 It happens.
But the problem does no appear when I debug, it appears when I run the app outside VS. When I click the close button that also contains ClipboardClear() explorer crashes. And it keeps on doing it till I restart the system.

Here's a part of the discussion I had with MS tech guy:

Quote

Your app, which doesn't load any code into explorer's address space, should not directly be causing it to crash. It is not the fault of your app that explorer is crashing. Rather, it seems that you have stumbled across a bug in Windows Explorer, similar to the Firefox 3.5.x case where the Private Browsing Mode was clearing out the clipboard (much like you seem to be doing) when Firefox would exit. This would cause heap corruption and an ultimate crash, in explorer.exe.

Re: Error while trying to clear clipboard in Windows 7 and C# 3.5

Re: Error while trying to clear clipboard in Windows 7 and C# 3.5

Posted 04 October 2010 - 05:15 PM

Well that's all.
When I double click the textbox, if the text box is not empty, it sets the control var to true, meaning that the clipboard is not empty and it copies the text to clipboard.
When I close the form by clicking the CLOSE button(the control box it's disabled) it clears the clipboard.
If you want me to post the entire code for that form it's OK with me but I don't see how that will help.
However I just realized I forgot to convert to string
I'll correct that and post back.