Archive Page 2

Tools I use for C# development

I’m often asked what tools I recommend for (general) .NET development, or at least which tools I use on a regular basis. Here’s a list:

  • Visual Studio Team Suite. I you can’t get Team Suite, get the Professional version. If you can’t get that one, use the Express version.
  • Code Analysis, which is built into Visual Studio Team Suite. FxCop does the same thing, and is free to download.
  • .NET Reflector. After MSDN Help (and possibly Google), this tool delivers the best documentation on the .NET Framework. Another free download.
  • The unit testing framework that is built into Visual Studio Team Suite. If you don’t have Team Suite, NUnit is a very good, free alternative, possibly in combination with NCover. TestDriven.NET integrates them into Visual Studio. All Free.
  • If I need to edit graphics such as icons or other bitmaps, I use Paint.NET with some additional plug-ins installed. Free as well.
  • Hardly needed at home, but for team projects at U2U we use Team Foundation Server.

There definitively are some other tools I should take a look at, for example WiX, or SandCastle and the SandCastle Help File Builder.

I you know of any must-have tools I didn’t mention, drop a comment.

Properties with property changed event, part 2

Last time I talked about properties with a changed event, I described the traditional pattern of having one event per property. But there is a disadvantage to that approach: since an event needs storage for a delegate, this technique wastes a considerable amount of memory if nobody subscribes to the events.

Continue reading ‘Properties with property changed event, part 2′

Paint.NET V3 looks great

I sometimes wonder how I do it, but in the middle of Tech·Ed I found the time to look at the third alpha release of Paint.NET. And I must say, it looks really good. The gradient effect, or rather the user interface to it, blows Photoshop out of the water. Those handles work really well, and not just on this effect by the way. The line/curve tool has them too, and I hope Rick adds them to the rectangle and ellipse and what have you tools as well. The Freeform Shape tool could use a bit of reworking along those lines too.

It looks like the plug-in API didn’t change, or at least my old plug-ins are still working. (reminder to self:) I need to check that out a bit further and maybe talk to Rick, because I believe there is room for improvement in that area, both in terms of functionality as well as performance.

But don’t get me wrong: this tool is great, and I encourage everybody who has ever touched up a photograph or made a drawing to download it and have a look. It’s good, fast, cheap on memory usage and cheap on money too (free!). You can even download the (C#) source in case you’re interested.

First day at Tech·Ed

It’s been an exciting day today at Tech·Ed.

I went to see Mike Pelton’s session on WPF, and I felt like a kid in a toy store, saying “Mammy, I want that too!”. It really looks nice, very developer friendly and powerful. This will definitely change the nature of Windows applications. And I don’t think it will just impact games and little nice tools that your grandma uses to burn DVD’s. The ease with which you can compose user interfaces will have a profound impact on business applications too, even if those don’t need the fancy graphics and 3D animations. That good old combobox will never look the same again.

The other session that was really impressive was the one on LINQ by Anders Hejlsberg. I had read about LINQ and knew it would be impressive, but the power of this thing was still amazing. I guess it’s a bit like a chainsaw, sometimes you need one but you don’t give it your kids to play with, too dangerous. But the thing is, if you handle it carefully, its’ a real powertool that can save you many hours of work. Especially if, like mine, most of your applications have that database in the back and add lots of XML to the mix.

Tomorrow will bring even more LINQ and WPF, but first I have to go to a party. Talk to you later.

Preparing for Tech·Ed: Developers in Barcelona

After a busy week and a bit of a flue, I’m getting ready to fly to Barcelona tomorrow. The entire U2U crew are going, so I’m looking forward to a week of fun and learning. What’s on my agenda?

I’ll definitely check out the sessions by Anders Hejlsberg. He’ll talk about LINQ and the other new features of C# 3.0.  The .NET Framework 3.0, WPF, WCF and WF are high on my agenda too. Add SQL Server and Office 12 to the mix and top it off with some architecture, security and performance sessions, and we have a week full of learning fun.

Obviously I’m looking forward to the parties as well, especially the country drink in the Habana Bar that U2U is organizing on Wednesday together with Microsoft Belux. I expect to meet some “long time no see” friends there.

With all that stuff going on, I’m not sure I’ll find the time to blog about it. But if I do, you’ll read all about it right here!

Close the windows, please!

We went on a safari yesterday, in Safari Park Beekse Bergen in the Netherlands. The kids loved it, and I must admit it is quite impressive to drive your car through the park with nothing but a thin window between you and the lions. They don’t look too hungry, but you never know!

It’s not as if the lions are the only big animals you can watch from just two meters away. Rhinoceros, elephants, zebras, and all sorts of deer are all quite impressive when you get so close to them. Not to mention the giraffes, when they start running towards you!

Definitely a family day out I can recommend!

Free e-book on Threading in C#

Even if you think you know all there is to know about Threading in C#, this free e-book is worth a read. And you can download it as a pdf too!

Properties with property changed event

I often coach or teach .NET developers, and I’m often surprised how some folks write the most complex programs and discuss amazing architectures, but can’t get the basics right. So I’m planning to write a series of posts on .NET basics. I’ll use C# as a language, but most topics will be equally applicable to Managed C++ or Visual Basic.NET.

In this first post, I want to talk about simple properties with a changed event, as you will often find them on classes used in Windows Forms data binding scenarios. Take as an example a “Name” property of type string. We’ll use a backing field called “name”. In VB you can’t rely on casing to differentiate between the field and the property, so you’d probably call the field “nameValue” or something. The getter will simply return the field, but the setter needs to raise the event in addition to setting the field.

According to .NET standards, the event will be of type EventHandler and be called NameChanged. Any other type or name, and Winforms data binding will not work.

Many people write something along the lines of

private string name;

public string Name
{
    get { return name; }
    set    
    {        
        name = value;
        if (NameChanged != null)
        {
            NameChanged(this, e);
        }
    }
}

public event EventHandler NameChanged;

But that has approach has two problems associated with it. The first one is the easiest to understand: the NameChanged event will be raised, even if the Name didn’t really change. Let’s say the value of Name is null and I write

Name = null;

That will raise the event, even though nothing changed. That could result in wasted processing or worse. In the case where two such properties are bound to each other via their events, any assignment to either of them would cause an infinite recursion and a stack overflow. So you need to test if the value really changed before raising the NameChanged event.

The second problem has to do with inheritance. If your class might be used as a base class for derived classes, you need to give those derived classes an easy and efficient mechanism to react to a property change. Raising an event and then subscribing to that event yourself doesn’t count as efficient. So what we do instead is create a protected virtual method that raises the event. This allows derived classes to override the method to be notified of property changes. Simple, clean and efficient. According to .NET standards, we’ll call the method OnNameChanged. Event raising methods like this one have a single parameter of type EventArgs (or, in the general case, a class derived from EventArgs). That yields the following implementation:

private string name;

public string Name
{
    get { return name; }
    set
    {
        if (value != name)
        {
            name = value;
            OnNameChanged(EventArgs.Empty);
        }
    }
}

public event EventHandler NameChanged;

protected virtual void OnNameChanged(EventArgs e)
{
    if (NameChanged != null)
    {
        NameChanged(this, e);
    }
}

You can of course extend this basic pattern. For example you could make the property virtual as well, although that would slow it down considerably. Anyway, the pattern as above is quite a bit of typing as it is, and will cover most cases.

In part 2 of this series, where we talk about an alternative approach: using the INotifyPropertyChanged interface.

Hello world!

In AustriaSome people keep on asking me why I don’t blog. It seems it’s just something one should do in the twenty-first century. Then again, I often enjoy reading other people’s blogs, so maybe I should indeed return the favor. I looked around a bit for a site to host it, and I found WordPress.com. It looks good (technically speaking, I’ll work on the graphics…), and it seems to have the features I want (including the must have RSS feed).

So now I have to deal with the white sheet of paper, and fill it. I guess I’ll be sharing experiences from my boring hobbies and fun work with you. Expect technical stuff, mostly on .NET. Geeky stuff maybe. But you might also get to see some of the pictures I shoot. I might even be funny from time to time. Well, I’ll leave that up to you to decide.

Talk to you soon.

« Previous Page