Saturday, January 22, 2011

How to Prevent Visual Studio from Timing Out While Debugging an Application

For some time now I've experienced the annoying phenomenon of Visual Studio timing out very quickly during a debugging session. I was never able to precisely nail down exactly how long the timeout duration was but it seemed like a couple of minutes.

I'd searched for a solution to this problem before but could never find one. Today I did. Unfortunately the author wasn't very verbose about how to find specific items referred to in the solution so I thought I'd do so here in the hopes that it will help others.

Note: Much to my disappointment, this only works if you get VStudio to attach to IIS.  I have not yet found a way to configure the internal Web Development Server in a similar fashion.  :-(

For starters, on my workstation I am running Windows 7 Ultimate and Visual Studio 2008.  The aforementioned posting refers to changing a timeout value in Internet Information Services (IIS) 7.  I didn't have it enabled on my computer (only on a server) so the first thing I did was install it:
  1. Start → Control Panel → Programs and Features → Turn Windows features on or off (left column)
  2. In the dialog box that appears, simply check "Internet Information Services" and press OK.
  3. After about a minute, it appeared to have installed the necessary components, though no new options showed up in the Control Panel nor in the Administrative Tools section of the same.
  4. With no explicit way to run the IIS Manager, I went to Start and then typed the following into the Search textbox:  inetmgr
  5. To make it more readily available in the future I right-clicked on the "inetmgr" item that appeared from the search and chose "Open file location".
  6. I located "InetMgr.exe" in this folder and dragged & dropped a shortcut into the "Administrative Tools" folder (just hold down Shift + Ctrl to force a shortcut to be created).
  7. For security reasons it wouldn't let me but did ask if I wanted a shortcut placed on the Desktop.  Yes!
  8. I then moved the new shortcut into the Administrative Tools folder.  Other than a confirmation prompt, it let me do it.
  9. Finally, I renamed "InetMgr.exe" to "IIS Manager", confirming a prompt to finalize the name change.
Then I opened up the IIS Manager.  From the aforementioned posting it wasn't immediately obvious what to do.  But after a little trial & error I figured it out:
  1. Double-click on "Configuration Editor" (bottom row, left side).
  2. In the left column click on "Application Pools".
  3. In the center column click on the row beginning with "DefaultAppPool".  On my system it was the only one present.
  4. In the right column click on "Advanced Settings..."
  5. In the dialog box that appears scroll down a little to the "Process Model" section.
  6. You can either changed "Ping Enabled" to False to have an unlimited timeout or you can change the value of "Ping Maximum Response Time (seconds)" from the default of 90 to something else.  I opted for 900 seconds.

Tuesday, January 11, 2011

Input Parameters: One Better than Strings and Enums

The ASP.Net/C# project I'm working on has several methods that resemble this general pattern:
  public void UpdateDataTable(DataRow dataRow, object objFldName, object newValue)
    string fieldName = objFldName.ToString();
In times past the 2nd parameter would always be string fieldname but to increase data typing and reduce errors I started introducing Enums wherever possible.  In this particular example UpdateDataTable processes DataRows from several different DataTables.  As I have a different Enum for each DataTable's fieldnames and not one Enum for all DataTable fieldnames, a solitary Enum parameter type isn't possible.

I eventually realized that I could use the little trick of specifying a generic object data type and then convert each parameter value over to its string equivalent.  A simple trick, yes, but also an effective one!