Plunging into .NET Development

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


Saturday, December 31

One year of blogging

My first post on this blog was made on December 14, 2005. One year later, I notice that I made exactly 100 posts. Time for some reflection ...

Has my blog changed my (professional) life? Well, in a certain way yes! Let me try to explain it ...

Before I started blogging, I was already into all the technical stuff about .NET programming ... but more superficially. I read already a lot about different topics (books, blogs, magazines, ...) and I knew the basics pretty well, but I never took the time to explore it to the bone. Nowadays when I'm reading something interesting about a specific topic or dealing with a weird problem, I really try to dig deep into it and try to understand it completely. Because of this, I feel that I gained more insight in certain areas of .NET programming. Sometimes this digging results in a blogpost. One year of blogging also means that a part of my experience of that year is written down and I can always reach it and look things up when I need it.

Blogging remains personal. I mean that I'm completely in control about time and content of posting. When I don't feel like it or when I'm busy with something else, you won't see me posting because I have to. There's no deadline! I do this because I believe it's better for me and if I can share some knowledge with others in that way ... great! I really do appreciate all the positive feedback I've received about my blog and I'll try to keep up the good work, but I can't make that promise! I'm also subscribed to other blogs what makes me dependent on the people behind those blogs. Being subscribed to blogs is like subscribing to a service without a contract : you never know exactly what to expect. If you like it, you keep your subscription; otherwise you unsubscribe! No obligations. It's that simple!

If you consider to start your own blog, you must be aware that you will have to free a lot of time to write your own stuff and this won't be easy after a while. You will have to find your own rhythm. Blogging is definitely a learning process! What do you choose : quality or quantity?

I really don't believe that blogging is a waste of time. You get noticed (visibility) and it's good for your market value if you don't write too much BS.

I wish you all the best in 2006 and stay tuned!

Tuesday, December 27

Event Accessors

What properties mean for accessing private variables, that does Event Accessors for private events. In Visual Studio 2003 Event Accessors can only be used with C#. Luckily in Visual Studio 2005, this technique is available for VB.NET developers as for C# developers.

Event Accessors give you full control about subscribing to events and unsubscribing from events. Like properties you have the opportunity to perform some (business) checks prior to subscribing/unsubscribing. Really interesting if EventHandling is all over the place in your application. Were you already in a situation that certain EventHandling methods were executed way too many times? First of all this can have serious consequences for performance, but this can also result in unexpected behavior of your application. One solution : Event Accessors!

Instead of having a public EventHandler in your publisher class, you must create a private EventHandler, followed by the Event Accessor.

With the keywords add and remove you are able to do some pre- and/or post-processing. In Visual Studio 2003, add and remove are not shown in blue, but they act the same.

In the example below I prevented for example that a particular EventHandling method (value) can only be subscribed once to the MyEvent. The InvocationList (arrayOfDelegates) will be iterated to check if there's an exact match in the already subscribed list for the new EventHandling method (value) that wants to subscribe to the MyEvent. Only if the new method is not yet registered it will be added to the EventHandling list. That will prevent EventHandling methods to execute more than intended and this will always be good for performance!


Friday, December 23

Being more productive

Last Tuesday I gave an internal presentation at Compuware about how to be more productive with the .NET Framework and the Visual Studio IDE. I gathered enough tips & tricks for a two hour presentation and it was fun to do because all stuff could be demoed in Visual Studio. I deliberately paid more attention to tips & tricks that can be used with Visual Studio 2003 and the .NET Framework 1.1. From beta 1 of Visual Studio 2005 until the full release in November 2005, a hype has been created that Visual Studio 2005 and the .NET Framework 2.0 would be far more productive for developers. That may be the case, but we must not forget that a lot of us will still be developing software for several months (hopefully not years) with Visual Studio 2003 and the .NET Framework 1.1. The evening of the presentation it was shown that still a lot of features in the .NET Framework 1.1 are not fully adopted and there's still some room for improvement about how we write code in the old environment. In some next posts I'll try to cover some stuff I talked about.

Wednesday, December 14

Timers

Timers allow you to specify a recurring interval at which an event can be raised in your application. .NET offers three different timer mechanisms :
  • System.Windows.Forms.Timer
  • System.Timers.Timer
  • System.Threading.Timer
Last week we went live with another release of our application in production. A major change for our software was the implementation of role-based security. Because of this release I will certainly remember the differences between the first two timer-objects. In a Windows Service we used System.Timers.Timer objects and a lot of security-exceptions [Request for Principal failed] were raised when the role-based security was set to our classes.
  • System.Windows.Forms.Timer
    This timer is optimized for use in Windows Forms applications. This Windows timer is designed for a single-threaded environment where UI threads are used to perform processing. It requires that the user code has a UI message pump available and always operates from the same thread. A Tick event is raised at intervals based on the Interval property setting.
  • System.Timers.Timer
    The server-based Timer is designed for use with worker threads in a multithreaded environment. Server timers can move among threads to handle the raised Elapsed event, resulting in more accuracy (metronome-quality) than Windows timers. The System.Timers.Timer class will call the timer event handler on a worker thread obtained from the common language runtime (CLR) thread pool.
When using the System.Timers.Timer, be sure to set the appropriate Principal to the thread that will execute the Elapsed event because this worker thread won't inherit the Principal from the main thread. The Tick event of the System.Windows.Forms.Timer will always run on the main UI thread, but the Tick event won't be as accurate ...

Monday, December 5

Log on as a service

If you want to run a Windows Service under a custom account instead of Local System (default), be sure to add that custom account to the Log on as a Service group. Otherwise you won't be able to get the Windows Service started. Following error-message will be thrown at you : The *** service was unable to log on as *** with the currently configured password due to the following error : Logon failure, the user has not been granted the requested logon type at this computer.

You can add the custom user account in the Local Security Settings [Administrative Tools > Local Security Policy].



The Log on as a service determines which service accounts can register a process as a service.

Friday, December 2

Google Analytics

After all the good news I've heard and read about Google Analytics, this evening was the right time for me to download it myself and to see how it works in the week-end ...

But ...

Over the last week, we've experienced extraordinarily high demand for Google Analytics, so much that we've had to disable new signups to ensure the best possible user experience for our customers. We are aware that some of our users have experienced a slow-down in seeing their reporting data due to the huge demand, and we're working hard to make report data as fresh and current as possible.

Delivering excellent free products/services isn't enough these days. Being popular and always in the spotlights has apparently side effects ...

Update : I received my invitation code a few weeks ago and can now start exploring Google Analytics!