Asynchronous Programming with C# 5.0 & .NET 4.5 Session

March 26, 2012

This morning I gave a session on asynchronous programming with C# 5.0 at Microsoft offices in Ra’anana. Thank you all for attending, it was great fun! As promised, the presentation slides and demos are attached below (the Windows 8 demos can naturally be run on Windows 8 only). The session was recorded, so if you missed it, or just want to hear the same jokes again, the recording will be available in a few days – check out the MSDN blog for details of availability. Async Demos Async Metro Demo Presentation Slides

INotifyPropertyChanged implementation with C# 5.0

March 20, 2012

The INotifyPropertyChanged interface has become a very popular interface, typically used in MVVM scenarios (WPF/Silverlight). It looks simple, with a single member, which is an event, and its basic implementation by some data type may be something like this: class Book : INotifyPropertyChanged {     public event PropertyChangedEventHandler PropertyChanged;       protected virtual void OnPropertyChanged(string propName) {         var pc = PropertyChanged;         if(pc != null)             pc(this, new PropertyChangedEventArgs(propName));     }       string _name;     int _published;       public int Published {         get { return _published; }         set {             if(_published != value) {                 _published = value;                 OnPropertyChanged("Published");             }         }     }  ...

What happened to asynchrony with WebClient in .NET 4.5?

March 17, 2012

In the Visual Studio 2010 Async CTP, a bunch of extension methods have been added to the WebClient class, to facilitate the “awaiting” of C# 5.0, such as DownloadStringTaskAsync, which can be simply used like so: var wc = new WebClient(); string result = await wc.DownloadStringTaskAsync(""); One of the overloads present in the CTP accepts a CancellationToken, so that the operation could be cancelled by an external CancellationTokenSource. For example: async Task<string> GetData(string uri, CancellationToken token) {     var wc = new WebClient();     string result = await wc.DownloadStringTaskAsync(new...
no comments

Presentations I’ll be giving this month

March 13, 2012

This month turned out to be a busy one for me, at least as far as public presentations are concerned. All sessions are free of charge, but you should register – details follow: Parallel and Asynchronous Programming with .NET 4/4.5 and C# 5.0 This session is to be held on the 20th, at John Bryce offices in Tel Aviv. I will do a quick recap of tasks and the Parallel class, and then move to async programming with and without the new C# 5.0 features. I will be using VS 2010 and the recently released (beta) Visual Studio 11. Link to registration Async...

Static vs. Instance (vs. Extension)

March 9, 2012

Sometimes I teach a basic .NET & C# course. Among many other things, I discuss arrays. I mention that all .NET arrays derive from System.Array, and so get some functionality for free, such as sorting. Here’s a simple array: int a = new int; Now, the inexperienced student may type “a.”, opening the intellisense list box, and look for a method named Sort – after all, the instructor (me) said arrays support such an operation. The confused student can’t find any such method. Of course the problem is that sorting is...
no comments

Visual Studio 11 Beta–First Impressions

March 2, 2012

Visual Studio 11 Beta is out (along with Windows 8 Beta), so naturally, I installed it right away (I did create a restore point just in case…). I wanted to get some first impressions of VS 11, and this is the result. Installation Installing VS 11 was easier than ever, because there were no choices at all – just install and be done with it. No way to remove unneeded components. I don’t know if this is going to be the final install experience, but this is certainly new. I’m still not sure this is entirely a good thing,...