An Archived Managed World

This blog has moved to http://www.managed-world.com/blog

  Home  |   Contact  |   Syndication    |   Login
  473 Posts | 0 Stories | 394 Comments | 1292 Trackbacks

News

Twitter












Archives

Post Categories

Blog Roll

Saturday, December 19, 2009 #

If you are subscribed to my RSS feed, you shouldn't see this as FeedBurner should have redirected you automatically. This blog has moved to http://www.managed-world.com/blog. This site is now for archive purposes. Thanks!


Wednesday, October 21, 2009 #

This morning, Channel 9 launched the new Channel 9 Learning Center. From Channel 9, here’s a description of what the Learning Center is: “The Channel 9 Learning Center is the destination for free technical training on emerging Microsoft products and technologies. The Learning Center consists of a set of courses with each course including a set of videos, hands-on labs, and source code samples to get you up-to-speed quickly.”TrainingCourse

I’m pleased to say that Visual Studio 2010 is one of the first Training Courses that we have launched on Channel 9. Please welcome the Visual Studio 2010 Training Course

What is the Visual Studio 2010 Training Course? The Visual Studio 2010 and .NET Framework 4 Training Course includes videos and hands-on-labs designed to help you learn how to utilize the Visual Studio 2010 features and a variety of framework technologies including: C# 4.0, Visual Basic 10, F#, Parallel Computing Platform, WCF, WF, WPF, ASP.NET AJAX 4.0, ASP.NET MVC Dynamic Data.

Essentially, the Training Course is an online version of our Visual Studio 2010 Training Kit. In this first release of the training course, it contains a subset of the content that is actually present in the training kit. Of course, since it is an online delivery mechanism, we will continue to add more items from the training kit into this training course over the coming weeks and months.

This first version of the Training Course includes intro videos and labs on the following technology areas: managed languages, ASP.NET 4, data platform (ADO.NET and “Velocity”), WCF, WF, and Parallel Computing.

I hope you all enjoy the Visual Studio 2010 Training Course on Channel 9!


Tuesday, October 20, 2009 #

The Beta 2 version of DPE’s Visual Studio 2010 Training Kit is now live (you can find it at http://tinyurl.com/Beta2Training).

Training Kit

A training kit includes presentations, hands-on labs, and demos. This content is designed to help you learn how to utilize a variety of Visual Studio 2010 and .NET Framework 4 technologies.

The Beta 2 release of the Training Kit contains 15 presentations, 19 hands-on labs, and 13 demos. Many technologies are covered in this release, including: C# 4, VB 10, F#, Parallel Extensions, Windows Communication Foundation, Windows Workflow, Windows Presentation Foundation, ASP.NET 4, Entity Framework, ADO.NET Data Services, Managed Extensibility Framework, and Visual Studio Ultimate.

There’s a lot of content covered here. See for yourself:

Presentations

  • What’s New in .NET Framework 4
  • What’s New in Visual Studio 2010
  • Introduction to ASP.NET MVC
  • Introduction to Managed Extensibility Framework
  • Introduction to .NET RIA Services
  • Introduction to “Velocity”
  • Parallel Computing for Managed Developers
  • Web Deployment with Visual Studio 2010
  • What’s New in ASP.NET AJAX 4
  • What’s New in ASP.NET Web Forms 4
  • What’s New in C# and VB
  • What’s New in ADO.NET Data Services
  • What’s New in Entity Framework 4
  • What’s New in Windows Presentation Foundation 4
  • What’s New in Windows Workflow 4

Hands-On Labs

  • Introduction to ADO.NET Data Services
    • Exercise 1: Creating and Consuming ADO.NET Data Services
    • Exercise 2: Consuming ADO.NET Data Services using ASP.NET AJAX
    • Exercise 3: Extending Data Services with Service Operations and Interceptors
    • Exercise 4: Adding Client-Side Paging with Row Count
  • ASP.NET AJAX 4
    • Exercise 1: Leveraging a Client-Side Template
    • Exercise 2: Using the DataView Control
    • Exercise 3: Creating Custom Markup Extensions
    • Exercise 4: Declaratively Instantiating Behaviors
  • Creating Plan My Night – ASP.NET MVC Application
    • Exercise 1: Creating an ASP.NET MVC Application, Plan My Night
    • Exercise 2: Creating Entity Framework Data Model
    • Exercise 3: Adding AJAX For Searching Activities
  • Enhancing Plan My Night – ASP.NET MVC Application
    • Exercise 1: Adding Caching using “Velocity”
    • Exercise 2: Structuring an Application using MVC Areas
  • Introduction to ASP.NET Web Forms 4
    • Exercise 1: Controlling Server Control ClientIds
    • Exercise 2: Enabling Bi-Directional Routing Support
    • Exercise 3: Granular ViewState
  • Microsoft Office Programmability in C# and Visual Basic
  • Introduction to F#
    • Exercise 1: Types in F#
    • Exercise 2: Using the Let keyword
    • Exercise 3: Functions
    • Exercise 4: Lists
    • Exercise 5: Pattern Matching and Recursion
    • Exercise 6: Types and Discriminated Unions
  • Introduction to the Managed Extensibility Framework
    • Exercise 1: Using MEF To Dynamically Add Modules to an Application
    • Exercise 2: Dynamically extending a form
  • Introduction to “Velocity”
    • Exercise 1: Setting up and running “Velocity”
    • Exercise 2: Programming directly against “Velocity” as a generic object cache
    • Exercise 3: Using Velocity’s SessionState provider with ASP.NET
    • Exercise 4 (Optional): Configure “Velocity” Cache in a cluster
  • Introduction to Workflow 4
    • Exercise 1: Hello Workflow
    • Exercise 2: Refactoring Workflows
    • Exercise 3: The CodeActivity
    • Exercise 4: Dynamic Workflows with XAML
    • Exercise 5: Testing Workflows
    • Exercise 6: WorkflowApplication
    • Exercise 7: Adding If/Else Logic
    • Exercise 8: Error Handling
    • Exercise 9: Activity Designers
    • Exercise 10: Hosted Designer
  • Introduction to Parallel Extensions
    • Exercise 1: Parallelize existing algorithm using static Parallel helper class
    • Exercise 2: Create and run parallelized Tasks
    • Exercise 3: Using the Task<T> class to create and run tasks that return a value
    • Exercise 4: Parallelizing LINQ queries using PLINQ
  • Test-Driven Development in Visual Studio 2010
  • WCF Service Discovery
    • Exercise 1: Ad-Hoc Discovery
    • Exercise 2: Metadata Extensions
    • Exercise 3: Announcements
    • Exercise 4: Discovery Proxy
    • Exercise 5: Legacy Discovery
  • Web Development in Visual Studio 2010
    • Exercise 1: Using HTML Code Snippets
    • Exercise 2: Web.config Transformations
    • Exercise 3: Packaging and Deploying Web Applications
    • Exercise 4: Packaging and Deploying Web Applications for IIS
  • Building a Data-Driven Master/Detail Business Form using WPF 4
  • Multi-touch Gesture – MFC
  • Multi-touch WMTouch – MFC
  • Ribbon – MFC
  • Taskbar - MFC

Demos

  • ContosoAutomotive (Parallel Extensions + MEF + WPF)
  • AdventureWorks AJAX
  • ASP.NET AJAX Ten-In-One
  • Managed Languages Ten-In-One
  • Barrier
  • CountdownEvent
  • Hello Visual Studio 2010
  • Introduction to the Managed Extensibility Framework
  • Parallel Baby Names
  • Parallel For Loop
  • Parallel LINQ (PLINQ)
  • Parallel Tasks
  • “Velocity”

Enjoy!


Monday, July 13, 2009 #

In this episode of 10-4, we take a look at a new library in .NET Framework 4 and how it helps developers write applications that are more extensible and easier to maintain than before.

For more information on the Managed Extensibility Framework, make sure to check out its home on Codeplex: http://www.codeplex.com/mef.

For more 10-4 episodes, be sure to visit:
http://channel9.msdn.com/shows/10-4

10-4! Over and out!


Tuesday, June 09, 2009 #

One of the big areas of improvements coming to Visual Studio 2010 and .NET Framework 4 is in the area parallel computing. There are a LOT of new features and improvements to existing features here with this latest release of our developer tools.

Many people smarter and more capable than I have already written about most of this stuff, so there’s not much for me to add. What I did want to do though is to let you know all the places where you can find this wealth of information (and there is a lot of it). So, without further ado, here is a list of content for you if you are interested in Parallel Computing with Visual Studio 2010 and .NET Framework 4 Beta 1.

 

MSDN

What’s New…

Diving Deeper

Channel 9 Videos

More Oldie-But-Goodie Channel 9 Videos

Misc…

Enjoy! There’s a lot here to digest. We definitely live in exciting times :).

Do you know of some links that you like that I missed here? Feel free to let me know by adding a comment here.


Friday, April 17, 2009 #

As I’ve been writing more F# code and learning more about the F# language, I have found myself intrigued by how some surprisingly simple language features can combine with each other to enable us to write very expressive code. While I am still learning F# (and realize just how much more I have to learn), I’m hoping that sharing some of these thoughts will encourage others to dig into what I think is a very powerful language that a lot of us developers can learn from.

In this post, we’re going to talk about Infix Operators. Before we dive into F#’s implementation of infix operators though, let’s discuss what an “Infix” Operator actually is.

So what is an “Infix” operator? An infix operator is an operator that is expressed using a mathematical notation called infix notation. When it comes to these types of mathematical notations, there are three primary kinds: Prefix Notation, Infix Notation, and Postfix Notation.

Take for example the addition operator. The addition operator takes two operands that are then added together. Using infix notation, the operator is written between the two operands it operates upon. Prefix notation would have the operator before the operands, and postfix notation has the operator after the operands. So given the addition operator, the different notations would like the following:

  • Prefix notation: + 3 4 (definitely familiar to LISP-heads –> “(+ 3 4)”)
  • Infix notation: 3 + 4 (familiar to most of us developers)
  • Postfix notation: 3 4 + (an interest way used by Forth for one, a stack-as-first-class-citizen language –> “3 4 ADD”)

One of the things I love about F# is that infix operators are normal functions that you can easily define yourself. Let’s explore this concept a bit. Open up F# Interactive and execute the following command:

> (+);;
val it : (int -> int -> int) = <fun:clo@42>

Note: Surrounding the infix operator with “()” allows us to get at the underlying function that implements the infix operator, rather than the operator itself.

Heck, we can even call it like a normal function:

> (+) 3 4;;
val it : int = 7

You can see here that the addition operator is simply a function that accepts two integers and returns an integer (well, this isn’t technically true, but you can think about it this way for now; we’ll get into the difference in a different post). I said before we can easily define our own infix operator. How do we do that? Well, just for giggles, let’s go ahead and define our own add operator:

> let (|+) x y = x + y;;
val (|+) : int -> int -> int

After we define this function, we can use our new infix operator just like any of the other built-in infix operator:

> 3 |+ 4;;
val it : int = 7

Yes, it’s that simple.

Well, that’s a very quick look at a seemingly simple language feature that a lot of us developers tend to take for granted. In future posts, we’ll see how combining infix operators with other features in F# allows us to write more expressive F# code.


Tuesday, February 24, 2009 #

Well, I said I was going to be moving on to CountdownEvent, but I was wrong. there is one more aspect of using Barrier that I just had to share (thanks go to Stephen Toub on the Parallel Computing Platform team for bringing this up).

In my first Barrier post, I had mentioned:

Barrier is a great new synchronization primitive to use when there is a known amount of work to do that is being done by different workers that all have common synchronization points.

To make a long story short, this isn’t strictly true. Barrier can be used just fine when there is an unknown amount of work. The distinction between Barrier and other synchronization primitives isn’t about “known amount versus unknown amount of work”, it’s more about “usable once versus usable many times.” To explain this in more detail, let’s look back at the example from the last post (a Road Trip to Seattle).

Multiple Usages

First, it is perfectly allowed to use a Barrier more than once. Using the Road Trip metaphor, instead of going straight to Seattle after leaving the Gas Station, let’s have everybody stop for lunch on there way. So now there are two “sync points” that we have. First, we’ll wait for everybody to meet up at the gas station, then we’ll also wait for everybody to meet up for lunch after they’ve left the gas station.

Revising our DriveToSeattle method from the last post, we will simply call SignalAndWait() a second time to provide a second sync point where everybody meets for lunch:

static void DriveToSeattle(string name, TimeSpan timeDelay)
{
    // Perform some work
    Console.WriteLine("[{0}] Leaving House", name);
    Thread.Sleep(timeDelay);
    Console.WriteLine("[{0}] Arrived at Gas Station", name);

    // Need to wait for others
    sync.SignalAndWait();

    // Perform some work
    Console.WriteLine("[{0}] Leaving for Seattle", name);
    Thread.Sleep(timeDelay);
    Console.WriteLine("[{0}] Meet for lunch", name);

    // Need to wait for others
    sync.SignalAndWait();

    Console.WriteLine("[{0}] Leaving for Seattle", name);
}

In real-word usage of the Barrier primitive, this doesn’t have to be limited to two uses of the Barrier. We can use the Barrier any number of times we need to in order to provide these common synchronization points for our parallel code.

Unknown Number of Workers

I mentioned that it wasn’t strictly true that Barrier is great for a just a known amount of work. That’s because Barrier provides the functionality you need to even use it when the number of workers performing our work is unknown.

Back to our Road Trip. Dennis’s sister Dee is planning to come along on the Road Trip as well. However, she forgets to set her alarm and wakes up late. And unfortunately, Charlie, Mac, and Dennis have already left for Seattle. She still wants to go though so she plans to meet up with them for lunch.

What we need is for a way for Dee to flag “Hey guys! I’m coming!” And it just so happens that the Barrier class provides an AddParticipant method that we can use to make sure the extra “worker” (Dee in this case) is included the next time everybody waits for each other to “complete their work.”

In this case, Dee would simply “add herself” to the Barrier when her thread is spun up. To do this, let’s create a new DriveStraightToLunch method that will be used instead of the existing DriveToSeattle method we created before.

static void DriveStraightToLunch(string name, TimeSpan timeDelay)
{
    // "I'm coming along guys"
    sync.AddParticipant();

    // Meet for lunch
    Console.WriteLine("[{0}] Leaving for Seattle", name);
    Thread.Sleep(timeDelay);
    Console.WriteLine("[{0}] Meeting for lunch", name);

    // Need to wait for others
    sync.SignalAndWait();

    Console.WriteLine("[{0}] Leaving for Seattle", name);
}

And then we just spin up this new piece of work (added to our code in Main before all threads are joined):

... creation and start of Dennis thread

Thread.Sleep(TimeSpan.FromSeconds(6));
var dee = new Thread(() => DriveStraightToLunch("Dee", TimeSpan.FromSeconds(5)));
dee.Start();

dee.Join();
... join other threads

It’s that simple.

In Closing

I hope in the last two posts you’ve seen how useful the new Barrier synchronization primitive can be when writing Parallel Code. API-wise there really isn’t much to the new Barrier class. Of course, as is usual with writing parallel code, it’s learning to use it correctly or use it in the right situations that’s the tricky part :).

I would say "tune in next time when we chat about CountdownEvent” but considering this recent change of plans, I’m not going to tempt fate :). Later!


Monday, February 09, 2009 #

Over the coming months, I would like to take you on a whirlwind tour of a bunch of the new data structures and APIs being added to the Base Class Libraries (BCL) for .NET Framework 4.0. This will take us everywhere from new multithreading-oriented data structures like Barrier and CountdownEvent, to more basic structures like Tuple.

I’ll update this post with correct links as new posts are created…

Enjoy!


In this first stage of our Tour de BCL, we will be passing through the new Barrier class.

So what is a Barrier? Let’s take a look at the boring technical description for a Barrier:

A Barrier is a synchronization primitive that enforces the stopping of execution between a number of threads or processes at a given point and prevents further execution until all threads or processors have reached the given point.

I don’t know about you, but sometimes technical descriptions like the above just sound like “blah, blah, blah” to me. What does a Barrier really mean to me, as a developer. Let’s break it down a different way by looking at a specific real-life scenario.

Think of a Road Trip

Instead of looking at the technical description above, think of the concept of a road trip.

There are three friends, Mac, Charlie, and Dennis. They live in a small town south of Seattle but want to take a road trip up to Seattle. So Mac calls up Charlie and Dennis and says “Hey guys, let’s take a road trip to Seattle. Meet up at the local gas station and then we’ll all leave from there.” So now they all now they need to go to the local gas station, wait for all of them to show up, and then they’ll leave for Seattle together and follow each other there.

Barrier

Relating this scenario to some code, let’s say that Charlie, Mac, and Dennis are all individual threads that have one method of execution, the DriveToSeattle() method. Within that method, they are all going “to drive” to the same gas station and then continue to drive to Seattle.

If we don’t use the Barrier to synchronize the work (aka wait for each other to arrive at the gas station), each one of them will leave for Seattle the second they arrive at the gas station:

static void Main(string[] args)
{
    var charlie = new Thread(() => {
        DriveToSeattle("Charlie", TimeSpan.FromSeconds(1))
    }); 
    charlie.Start();

    var mac = new Thread(() => {
        DriveToSeattle("Mac", TimeSpan.FromSeconds(2))
    }); 
    mac.Start();

    var dennis = new Thread(() => {
        DriveToSeattle("Dennis", TimeSpan.FromSeconds(3))
    }); 
    dennis.Start();

    charlie.Join();
    mac.Join();
    dennis.Join();

    Console.ReadKey();
}

static void DriveToSeattle(string name, TimeSpan timeToGasStation)
{
    // Drive to gas station
    Console.WriteLine("[{0}] Leaving House", name);
    Thread.Sleep(timeToGasStation);
    Console.WriteLine("[{0}] Arrived at Gas Station", name);

    // Need to sync here

    // Perform some more work
    Console.WriteLine("[{0}] Leaving for Seattle", name);
}

BeforeBarrier

Well, that’s hardly a road trip. If I were in Mac’s or Charlie’s shoes when Dennis left for Seattle without me, I know I would be a little upset. We obviously don’t want that to happen. So we can use the new Barrier to make sure they all “wait up” for each other at the gas station.

Using the new Barrier class

So how do you use the new Barrier class? It’s actually quite simple.The cool thing is that there are really only three things you need to learn to use the Barrier for this simple type of scenario: a single constructor and two method calls (both of which take zero parameters). Yes, it’s that simple to use.

Let’s look at what our new code using Barrier looks like (the three bold lines are the new ones):

static Barrier sync;

static void Main(string[] args)
{
    sync = new Barrier(participantCount:3);

    var charlie = new Thread(() => {
        DriveToSeattle("Charlie", TimeSpan.FromSeconds(1))
    }); 
    charlie.Start();

    var mac = new Thread(() => {
        DriveToSeattle("Mac", TimeSpan.FromSeconds(2))
    }); 
    mac.Start();

    var dennis = new Thread(() => {
        DriveToSeattle("Dennis", TimeSpan.FromSeconds(3))
    }); 
    dennis.Start();

    charlie.Join();
    mac.Join();
    dennis.Join();

    Console.ReadKey();
}

static void DriveToSeattle(string name, TimeSpan timeToGasStation)
{
    // Drive to gas station
    Console.WriteLine("[{0}] Leaving House", name);
    Thread.Sleep(timeToGasStation);
    Console.WriteLine("[{0}] Arrived at Gas Station", name);

    // Need to sync here
    sync.SignalAndWait();

    // Perform some more work
    Console.WriteLine("[{0}] Leaving for Seattle", name);
}

AfterBarrier

You can see now that nobody leaves for Seattle until everybody has arrived at the gas station. Essentially, with every call to SignalAndWait(), the number of signals received by the barrier is incremented. Once the number of signals received reaches the number of participants the Barrier was constructed with, all threads are then allowed to continue execution. And that’s all it takes to leverage the new Barrier class being introduced into the BCL with .NET Framework 4.0.

But Jason... What is up with that line of code: “sync = new Barrier(participantCount:3);”? I mean, what the heck is “participantCount:3”? How is that valid syntax?

Well, that’s easy. This is a new feature in C# 4.0 called Named Parameters where you can actually use a parameter’s name to specify what a value applies to. This becomes very handy in two places: 1) when combined with Optional Parameters, and 2) when used to clarify “magic numbers” (or “magic strings”, “magic booleans”, etc.) without having to introducing a temporary variable.

In this case, I could have left out participantCount and written just “sync = new Barrier(3);”. But I personally don’t like a magic number like “3” just floating around like this and Named Parameters give me an easy way to provide more context about the value “3”.

In Closing

So let’s look back at that boring technical description again:

A Barrier is a synchronization primitive that enforces the stopping of execution between a number of threads or processes at a given point and prevents further execution until all threads or processors have reached the given point.

Think about it this way:

  • “stopping of execution between a number of threads...” = waiting for each other to arrive
  • “… at a given point” = the gas station
  • “prevents further execution until all threads… have reached the given point” = can’t leave for Seattle until everybody shows up

See? Nice and simple!

Barrier is a great new synchronization primitive to use when there is a known amount of work to do that is being done by different workers that all have common synchronization points. However, if the amount of work needing to be done is not well known beforehand, Barrier is not the greatest primitive to use. Next we’ll look at another new synchronization primitive coming in .NET Framework 4.0 that is great to use when the amount of work is not known: the CountdownEvent.

I hope you all enjoyed this first stage in our Tour de BCL. Until the next stage, we’ll see you later.


Sunday, January 04, 2009 #

Here's a sneak peek at a project/library I'm currently working on:

include Microsoft::Xna::Framework
include Microsoft::Xna::Framework::Graphics
include RubyXna

class FluxxGame < RubyXnaGame
    def initialize
        self.background_color = Color.black
    end

    def load(loader)
        @font = loader.load_font("Title")
    end

    def render(renderer)
        renderer.draw_text(@font, "Fluxx, v0.1", Vector2.zero, Color.white)
    end
end

The combination of IronRuby and XNA Game Studio is proving to be pretty darn fun!