Certification News

During the week end I learned that I passed the "70-503: Windows Communication Foundation" beta exam. 🙂

Meanwhile, beta exams are still (through May 4th) available for ADO.NET 3.5 and ASP.NET 3.5.

70-561 – beta code = 561B1

70-562 – beta code = 562B1

Source: http://blogs.msdn.com/gerryo/archive/2008/04/02/asp-net-and-ado-net-beta-exams-extended.aspx and http://blogs.msdn.com/trika/archive/2008/04/18/net-framework-3-5-certifications.aspx

MVP News

Last Tuesday (April 1st), my MVP award was renewed. Yessss!
Among the benefits of being an MVP are:
  • MSDN Subscription
  • TechEd Subscription
  • MVP Bucks to spend on Microsoft Online Store
  • MVP Global Summit
You can choose to receive media for MSDN or Technet, or you can get both online.
 
Next Friday, I’ll be flying to Seattle for my first MVP Global Summit.
I really don’t know what to expect. The agenda really didn’t catch my eye except for a couple of sessions.
Let’s see if I’ll find things more interesting once I get there.
 
As a side note, I’ll be in New York for a couple of days after the Summit. It’ll be my first time there.
The weather is cold this time of the year. I hope I get to see some snow!
 

IIS 7 for Developers

Next Tuesday (March 18th, 2008), I’ll be talking (in Portuguese) about the new features brought by IIS 7 from a developer’s perspective.

From Microsoft Events web site:

Idioma(s):
Português.

Produto(s):
Internet Information Server.

Público(s):
Desenvolvedores.

Mercado Relacionado:
Serviços Profissionais.

Duração:
60 Minutos

Data de Início:

terça-feira, 18 de março de 2008 12:00 Brasília

Visão Geral do Evento

Palestrante: Alfred Myers Jr.

O IIS7 é o Web Server mais flexível, extensível e customizável do planeta. Neste webcasts apresentaremos um tour do IIS7 e demonstraremos os grandes benefícios que ele oferece para os desenvolvedores. Aprenda mais sobre o modelo extensível end-to-end no IIS7. Iremos mostrar também o novo configuration system and como este recurso é fácil para construir aplicações, incluindo o IIS configuration através de um simples XCopy. Mostraremos também o suporte dentro do IIS7 para as mais comuns liguagens de programação Web tais como PHP e ASP.NET.

 

https://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032357568&EventCategory=4&culture=pt-BR&CountryCode=BR

Back to Volta

Today I took the afternoon to take another look at Windows Live Labs Volta.

The idea of deferring the application partitioning to the last minute may be good for some types of projects but translating “X” (IL in this case) into JavaScript was something I’ve been wanting since the ASP + VB6 days!

I always thought that writing code in general and data validation code in particular for the server and then for the client was a tedious and error prone task.

At those days I had to write validation code in VB6 for the server and then rewrite it again in JavaScript for the client. Besides being tedious, it is an error prone task because you had two places to maintain the code as validation logic evolved.

Today I decided to test this with some legacy code I have here. I was thinking on getting some document number validation code I have here, but I stumbled across a function that translates currency amounts into their textual equivalents. Not sure how to say this in English, but the idea is to translate “1,234.56” into “Um mil, duzentos e trinta e quarto Reais e cinquenta e seis centavos”. That is “One thousand, two hundred and thirty four Reais and fifty six cents” in Portuguese.

I got this code originally written in Clipper from a magazine back in 1993.

Sometime later I rewrote it in Access Basic 2.0. A couple of years later ported it to Access 97’s VBA and at last VB 6. I have not touched it since 2000.

I ran the project through Visual Studio 2008 VB project Converter, made a couple of tweaks (really!), and added the project to my Volta test solution configured to run in Debug mode and voila! It worked like a breeze!

The important part is that I converted the project to a normal VB Class Library. Not a Volta Class Library. That implicates that I could theoretically use any any library that does not have dependencies on anything not supported by Volta and have it flow as JavaScript to the client side.

That must be what Erik Meijer means when he says "Volta stretches the .NET platform to cover the Cloud.”!!

It is important to notice however, that when you run the code in Debug mode, you are really running the IL version of it. I’m not yet sure how the magic works. Give me time!

As soon I tried to run it in Release mode, the page started complaining about unsupported features such as the Decimal constructor that accepts a Double or somewhere in the VB string helper functions trying to get a CultureInfo.

This is comprehensible since the technology is in its very early stages.

I tried equivalent BCL types and members without using the Visual Basic helper functions, and they worked so as soon as I find more time, I’ll try to fix it. I could simply try to isolate the helper functions giving me trouble and fix those pieces of code, but I’m more inclined to rewrite it in C# since it is not too much code and I have not been programming seriously in VB since 2005.

Anyway I’ll decide the route another time.

Stay tuned!

Volta

I just watched the Channel 9’s two part video with the Volta team and I have to say that it was mind blowing.

Volta has some really interesting ideas on how to simplify the development of distributed applications.

On the second part they get into the details of some of the obstacles they found translating IL into JavaScript such as JavaScript’s lack of a goto statement and how they got around it: using a while loop and a switch statement – a trick much like what C# does to implement “yield return”.

Other interesting thing was how they used exceptions to simulate multi-threading within the browser.

Really cool stuff worth watching!

The link below points to a post on the Volta Team Blog on Microsoft Live Labs which points to the Channel 9 videos. You also be able to get to the rest of the blog from there.

http://labs.live.com/volta/blog/Volta+On+Channel+9.aspx

Enjoy!

Yielding surprises

Last month I was working on a bug in a service I developed a couple of months ago.

The service consists of a Windows Service that coordinates an unspecified amount of secondary Windows Services that are in charge of collecting web site metrics.

Metrics collection is made at intervals specified in a configuration file. During development and stabilization I used very short time intervals from one second to one minute to stress garbage collection and resource consumption. With the intervals tested, the services were working properly.

Earlier this week, the service was being deployed and the guy in charge reported that above two and half minutes, the services stopped collecting metrics.

I did some tests with a five minutes interval and everything worked fine, but when I increased the interval to ten minutes I started to get SynchronizationLockException.

The weird part was that the exception was being thrown by the closing curly brace of a lock statement:

public IEnumerator<INavigator> GetEnumerator() {

    while (!this.disposing) {

        if (this.availableNavigators.Count == 0) {

            this.synchronizer.WaitOne();

        }

        lock (this.availableNavigators) {

            if (this.availableNavigators.Count != 0) {

                yield return this.availableNavigators.Dequeue();

            }

        } // The exception was being throw here.

    }

}

 

I went on to investigate the situations in which a SynchronizationLockExceptions could be thrown only to learn that:

“The exception that is thrown when a method requires the caller to own the lock on a given Monitor, and the method is invoked by a caller that does not own that lock.

SynchronizationLockException is thrown by calling the Exit, Pulse, PulseAll, and Wait methods of the Monitor class from an unsynchronized block of code.”

Putting it another way: The thread that calls Monitor.Exit has to be the same that called Monitor.Enter in the first place.

Well… What does this has to do with our case? Being a smart reader as you are, you may already know that a lock statement gets translated into calls to Monitor.Enter and Monitor.Exit by the C# compiler. From the C# spec:

“A lock statement of the form

lock (x)

where x is an expression of a reference-type, is precisely equivalent to

System.Threading.Monitor.Enter(x);
try {
     
}
finally {
      System.Threading.Monitor.Exit(x);
}

except that x is only evaluated once.”

Well… Even then the code should be running on the same thread between the Enter and the Exit.

Let’s take another look to our code – this time with calls to Monitor instead of using lock directly.

public IEnumerator<INavigator> GetEnumerator() {

    while (!this.disposing) {

        if (this.availableNavigators.Count == 0) {

            this.synchronizer.WaitOne();

        }

        object localReference = this.availableNavigators;

        Monitor.Enter(localReference);

        try {

            if (this.availableNavigators.Count != 0) {

                yield return this.availableNavigators.Dequeue();

            }

        }

        finally {

            Monitor.Exit(localReference);

        }

    }

}

 

This code transformation ringed a bell. Besides lock, “yield return” also gets translated into a set of other instructions. The generated code is indeed much more sophisticated than the lock case since it involves generating a state machine for managing the return point during subsequent calls of the method.

If you haven’t had a chance to use yield return or even study it, it’s a very interesting construct that permits you return a value and the next time you enter the method, code starts executing at the line immediately after the last line executed the last time you were in the method (the yield return line).

Under the covers, the C# compiler creates a new class that implements a state machine that keeps track of the line to be executed the next time the code enters the method.

So in our example, the code exits the method before passing through Monitor.Exit (it’s already starting to smell bad), but when coming back it is still the same thread. Or isn’t it?

Looking through the stack I find that this code is being called by a System.Threading.Timer which uses the thread pool to do its work.

Now a little parenthesis about threads and the thread pool: When you need to do work asynchronously it’s common to spawn a thread to do the work and eventually get the results later.

Creating thread is an expensive operation. You have to create kernel objects, allocate some space for the stack and some other stuff so it has become widespread use creating threads and instead of destroying it after it completes its job, we return it to a thread pool so it can be used later for accomplishing another task.

The .Net’s thread pool is smart enough to create new threads when needed and also to destroy them when they are no longer needed.

When you have little bursts of work at small intervals between them, the chances are that each job will be accomplished by the same thread.

On the other hand, if there is a long interval between job batches, the chances are that the thread becomes idle for too long and then the CLR gets rid of it.

So what was happening in this case was that once somebody configured a long enough interval the code was being executed by another thread causing a SynchronizationLockException to be thrown.

To get rid of the exception, I had to move the “yield return” out of the lock block so the code became like:

public IEnumerator<INavigator> GetEnumerator() {

    while (!this.disposing) {

        INavigator navigator = null;

        if (this.availableNavigators.Count == 0) {

            this.synchronizer.WaitOne();

        }

        lock (this.availableNavigators) {

            if (this.availableNavigators.Count != 0) {

                navigator = this.availableNavigators.Dequeue();

            }

        }

  yield return navigator;

    }

}

 

The lesson to be learned is that “yield return” should be used cautiously, even more when used inside constructs that get translated into other code as is the case with “lock” and “using” since the result may not be exactly what we are expecting.

FSRM COM API documentation hits the streets

Back in March I wrote about my findings regarding the API of a feature introduced in Windows Server 2003 R2 called File System Resource Manager (FSRM).

At the time these APIs were not documented, but with the eminent release of Windows Server 2008, Microsoft released the documentation for the COM API at MSDN Library. These aren’t yet the managed libraries I’ve been waiting for, but at least we can safely start doing Interop with the COM version without fear of changes in the API! 🙂

Lisa Feigenbaum & Amanda Silver on Codificando .NET e-magazine

This week, Codificando .NET released the November’s issue of their e-magazine.

It brings an interview I did back in September when I was at the Microsoft Campus in Redmond.

We talked about their careers and about features coming in VB 2005 and got a glimpse on what may show up on post Orcas.

The magazine is in Portuguese, but you can see the original video in English here:

 

 

Bring on the VB Ladies!

70-502 WPF Beta Exam Released!

Microsoft Learning released the beta exam for WPF 70-502 (71-502 while in beta) and you can schedule it for free at Prometric using the following promo code: 502B1*

So prepare yourself and good luck!

Here are a couple of good books on the topic:

Windows Presentation Foundation Unleashed (WPF) (Unleashed)

Windows Presentation Foundation Unleashed (WPF) (Unleashed)

I’m currently reading this one and I have to say that I’m very impressed. The book is all in full color. Sometimes too much color 🙂 But Adam Nathan really knows his stuff.

 

Applications = Code + Markup: A Guide to the Microsoft  Windows  Presentation Foundation (Pro - Developer)

Applications = Code + Markup- A Guide to the Microsoft Windows Presentation Foundation (Pro – De

This one is from Charles Petzold. After hearing so much about him, I got a little disappointed with the first book from him I got in my hands: Programming Windows with C# (Core Reference). This new one however was highly recommended, so I bought it and I’ll give it a try probably after reading Nathan’s book.

*Promo code courtesy of Manoj Agarwal.