Plunging into .NET Development

Weblog Pieter Gheysens
Microsoft .NET Development - C# - Enterprise Library - Visual Studio 2005 Team System - Compuware DevPartner - ...
 


Thursday, August 31

Elapsed event of Timer not raised

This bug caused us a lot of trouble.
In the event handler for the Elapsed event of the Timer object, if you call the Stop method of the Timer object, the reference to the Timer object is lost. The garbage collector then reclaims the memory that is associated with the Timer object. Later, even if you call the Start method of the Timer object to raise the Elapsed event, the call does not work. The Elapsed event is not raised. Typically, this problem occurs if the computer that is running the application is under a heavy load or if many timer objects are running.
That was exactly what was happening in our code. We stopped the timer at the start of the Elapsed event to prevent Timer Event Reentrance. In the finally block we re-started our timer again ...

private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

{

   try

   {

      //stop timer

      timer.Stop();

 

      //Logic here ...

   }

   catch (Exception ex)

   {   }

   finally

   {

      //restart timer

      this.timer.Start();

   }

}


At irregular points of time one (or more) of our Timers (System.Timers.Timer) stopped firing their Elapsed event in the production environment. First we extended our logging to see what was exactly causing this problem and we were hoping that we would remark some exceptions/warnings in our logfiles. But, as you guessed : no sign of meaningful logging. Furthermore we could not reproduce this behaviour in our other environments (Developent - Testing - Quality). We were also questioning if we were using the correct Timer class (see a previous post and this post from Gabriel Lozano-Morán)?

Finally I bumped into the Knowledge Base Article that gave me the answer. A hotfix is made available by Microsoft [Prerequisite : .NET Framework 1.1 SP1 - determine Framework version]. These things are damn hard to debug/test! I hope this helps if you're in a similar situation.

Wednesday, August 23

Suppress warning CS1591 for strongly typed datasets

In some projects of our solution (.NET 1.1) we have a lot of strongly typed DataSets with their generated .cs files. Because of the generated code we are faced with tons of warnings like warning CS1591: Missing XML comment for publicly visible type or member ‘x'] in our Build Output. Furthermore this is really annoying if you treat warnings as errors!

An easy way to suppress these warnings in your projects is to enter the warning-id in the property build page of your project.


Friday, August 18

Access to master pages

In ASP.NET 2.0 it's possible to create a strongly typed reference to the master page by creating a @ MasterType directive ...

In my master page for example I have a HeaderTable at the top of the page, a ContentPlaceHolder for the body in the middle of the page and a FooterTable at the bottom of the page. Now, I want to hide the FooterTable in a web page that also uses the master page. How to do this programmatically ...

In the master page I've created a public property for the FooterTable.

public partial class MasterPage : System.Web.UI.MasterPage

{

    public HtmlTable FooterTable

    {

        get

        {

            return this.tableFooter;

        }

        set

        {

            this.tableFooter = value;

        }

    }

 

    protected void Page_Load(object sender, EventArgs e)

    {

 

    }

}


Secondly I've added the @ MasterType directive to the aspx-page after the usual @ Page directive.

<%@ MasterType VirtualPath="~/MasterPage.master" %>


Adding this directive lets you point (strong typing) directly to the public properties of the master page and that's how I've hidden the FooterTable in the Page_Load event.

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        this.Master.FooterTable.Visible = false;

    }

}

Animation in web pages

Today I noticed occasionally that animated gif-images were not displayed with animation in my webbrowser. I didn't know that this is a setting you could turn on/off and apparently it's turned off by default on Windows Server 2003.


Tuesday, August 15

Enterprise Library v2.0 : log to database

Last week-end I've been playing with the Logging Application Block of the Enterprise Library v2.0 to setup logging to a database ...

How to setup logging to a database with EntLib v2.0?
  1. Create logging database with tables and stored procedures
    Script can be found in [Install Folder]\Microsoft Enterprise Library January 2006\src\Logging\TraceListeners\Database\Scripts.
  2. Create new configuration file with the Enterprise Library Configuration Tool.
  3. Add Data Access Application Block and set connectionString to logging database.
  4. Add Logging Application Block and add a Database Trace Listener to the Trace Listeners.
  5. Set DatabaseInstanceName and formatter on created Database Trace Listener.
  6. Add reference to the created Database Trace Listener in the general category.
  7. Add references Microsoft.Practices.EnterpriseLibrary.Logging and Microsoft.Practices.EnterpriseLibrary.Logging.Database to your project.
  8. Write some code to log to the database.


            try

            {

                throw new Exception("My Special Exception");

            }

            catch (Exception ex)

            {

                //Logging

                LogEntry logEntry = new LogEntry();

                logEntry.Message = ex.ToString();

                logEntry.Title = ex.Message;

                logEntry.Priority = 1;

                logEntry.Severity = System.Diagnostics.TraceEventType.Error;

 

                Logger.Write(logEntry);

            }



Don't forget the reference in your project to Microsoft.Practices.EnterpriseLibrary.Logging.Database. Otherwise you will end up with the Invalid TraceListenerData type in configuration error.

Thursday, August 10

VISUG - Guidance Automation Toolkit

Yesterday evening, Jelle Druyts gave an excellent presentation for the VISUG on the Guidance Automation Toolkit [GAT] at Compuware. Jelle gave a nice overview of the powerful possibilities of the Guidance Automation Toolkit and showed the ins and outs live in Visual Studio. Really powerful stuff! On his blog you can already find the slides he presented yesterday. He has been really busy with the exploration of the GAT lately : you can also find 6 interesting posts about it ... Some more Belgian VISUG news for those who don't know yet ...
  • Our VISUG President and my good friend Steven Wilssens will leave Belgium to join Microsoft Corp. in October 2006 as a Program Manager. Therefore the current VISUG Board is a little bit revised : Peter Himschoot is appointed as our new President, while Steven and I will temporarily fulfill the Vice President(s) function. New elections will be held in February 2007.
  • Next VISUG sessions:
Feel free to contact me for more information about the VISUG or send me your ideas, topics, suggestions, ...

Sunday, August 6

Training vs Experience

A slogan I noticed today on a calendar (no source) :

Training is learning the rules. Experience is learning the exceptions.

Tuesday, August 1

ASP.NET 2.0 Configuration : Profile Tab ?!

One of the improvements in ASP.NET was the centralization of all configuration settings in a web.config file (XML). In ASP.NET 1.0 and 1.1, you still had to manually edit your settings in angle brackets. In ASP.NET 2.0 we can use the Web Site Administration Tool (menu Website > ASP.NET Configuration) to do some configuration. This week-end I came to the conclusion that the Profile Tab is missing in the final release of Visual Studio 2005!? I'm sure that I have seen the Profile Tab in an earlier version! What happened with the Profile Tab? Anyone an idea why it's been removed from the final release of Visual Studio 2005?

Luckily it's still possible to use the Profile feature in ASP.NET, but you have to configure it manually in the web.config file ...

The ASP.NET profile feature associates information with an individual user and stores the information in a persistent format. Profiles allow you to manage user information without requiring you to create and maintain your own database. In addition, the ASP.NET profile feature makes the user information available using a strongly typed API that you can access from anywhere in your application.

By the way : did you know that you can easily modify/extend the Web Site Administration Tool? You can find all source in (drive):\(WindowsPath)\Microsoft.NET\Framework\v2.0.50727\ASP.NETWebAdminFiles. Finally it may still be possible to create my own Profile Tab ...

Links