Saturday, November 7, 2009

Visual Studio Crashes on Async Callback to User Control

I am working on some code for a client that involves a tabbed interface containing a User Control in each tab. This nicely separates out all of the UI logic for each of the tabs so you don't end up with one monster file with every control from every tab. Trying to be a considerate UI citizen, I am trying to populate the ListBox controls asynchronously using a BackgroundWorker.

When the user clicks on the tab, it populates a loading message as the first item for the listbox and then makes a call to the database to load the items. When the database call is finished, it clears the listbox before populating it with the data. I'm not sure if it's the clearing of the listbox or the population of the data but as soon as the control is placed on the tab, Visual Studio actually tries to execute the code of the user control! This is happening in design time! I have had several odd behaviors because of this behavior of Visual Studio.NET 2005 and 2008.

At another point in the project, I put in some error handling in a similar tab-contained User Control that would throw an exception if the database string wasn't populated. Visual Studio would execute my code as soon as the tab was selected in design time, throw my exception and then close because the code was calling Applcation.Close after telling the user to fix the connection string.

This seems to me to be a serious bug on Microsoft's part and I submitted it to Microsoft Connect.

No comments:

Post a Comment