DCSIMG
October 2010 - Posts - Arik Poznanski's Blog

Arik Poznanski's Blog

It CAN be done with .NET

News

MVP

MCC

CodeProject MVP

MCPD

MCTS

Subscribe to my blog by email

Arik Poznanski LinkedIn Profile

Email: arik.com at gmail dot com
or, use this form

Locations of visitors to this page


Sela Group

Sela Canada

DZone MVB

Links

Official Blogs

WPF / SL Blogs

Developers Blogs

October 2010 - Posts

PDC 2010: Taking Advantage of Pinned Sites with Internet Explorer 9 and Windows 7

Following is a summary of the session “Taking Advantage of Pinned Sites with Internet Explorer 9 and Windows 7” presented by Israel Hilerio, Program Manager in Internet Explorer Team at Microsoft, in PDC 2010.

image

This talk shows how you can add integration of your site into the Windows 7 taskbar.

image

Pinned Sites

Goals for having pinned sites in Internet Explorer 9:

  • Closer relationship between users and their favorite sites
  • Allow web sites to promote their brand outside of the browser
  • Seamless integration of web sites into desktop experience
  • Web sites interact with users like Windows applications
  • Web sites control the user interaction and navigation
  • Available to any website

Pinning a Site to the Taskbar

  • All pinning is user initiated! No public APIs for pinning.
  • Two ways to pin a website
    • Tear off a tab, and drag it to the Taskbar
    • Drag the favicon from the address bar to the Taskbar
  • After a site is pinned, the browser UI is updated to promote the site
    • The back and forward buttons are colored after the favicon
    • The site’s favicon brands the browsing experience
    • Selecting the top left favicon navigates users to the initially pinned page

Setting Site-wide Properties

Notice that the following functionality should be implemented by the web developers of the site using meta tags.

  • Setting application name in the taskbar:

<meta name="application-name" content="Sample Site Mode Application"/>

  • Setting a desktop tooltip

<meta name="msapplication-tooltip" content="Start the page in Site Mode"/>

  • Setting a start URL, that is the base URL that will be pinned to the taskbar

<meta name="msapplication-starturl" content="http://example.com/start.html"/>

  • Define the ideal size for the web site, this will affect the initial window size

<meta name="msapplication-window" content="width=800;height=600"/>

  • Define the colors of the navigation buttons

<meta name="msapplication-navbutton-color" content="red"/>

  • Setting jump list tasks

<META name="msapplication-task" content="name=Task 1;action-uri=http://host/Page1.html;icon-uri=http://host/icon1.ico"/>

Jump List Categories

To create dynamic jump list categories you must use the JavaScript APIs:

  • Create the category list

window.external.msSiteModeCreateJumplist('List1');

  • Create list items

window.external.msSiteModeAddJumpListItem('Item 1', 'http://host/Item1.html', 'http://host/images/item1.ico');

  • Display list

window.external.msSiteModeShowJumplist();

  • Clear list

window.external.msSiteModeClearJumplist();

Overlay Icons

To use overlay icons you again use the JavaScript APIs:

  • Set overlay icon

window.external.msSiteModeSetIconOverlay('http://host/images/overlay1.ico', 'Overlay 1');

  • Hide overlay

window.external.msSiteModeClearIconOverlay();

Thumbnail Toolbar Buttons

This allows you to set button on the thumbnail image in the taskbar:

  • Adding a button

btn1 = window.external.msSiteModeAddThumbBarButton('http://host/images/button1.ico', 'button 1');

  • Setting an event handler

document.addEventListener('msthumbnailclick', handler1, false);

  • Show thumb bar

window.external.msSiteModeShowThumbBar();

Flashing Taskbar Button

Can be used to signal users that the site requires attention

window.external.msSiteModeActivate();

Security Model

Some notes and limitations on the features seen:

  • The Start URL is bound to the domain of the webpage
  • In a Jump List task, any destination is valid
  • When using JavaScript APIs, the URLs are bound to the domain of the webpage

Best Practice

  • Start URL should point to a destination page with the meta-tags
  • Create all thumbnail buttons on the start URL page
  • Hide thumbnail buttons on every page unload
  • Define multiple resolutions on the same ICO file for the favicon of the site

Limitation

  • Jump List Tasks: Maximum of 5 tasks
  • Jump List Categories: Only one category, maximum 20 items, 10 items by default
  • Thumbnail toolbar buttons: Maximum 7 buttons

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

PDC 2010: 3-Screen Coding: Sharing code between Windows Phone, Silverlight, and .NET

Following is a summary of the session “3-Screen Coding: Sharing code between Windows Phone, Silverlight, and .NET” presented by Shawn Burke, Architect on the Silverlight team, in PDC 2010.

image

Portability Story

Lessons learned

  • Sharing code is hard
  • Sharing UI is harder

Writing portable code has a rocky past..
The whole “Write-Once-Run-Everywhere” theme didn’t work so much.
Just consider writing code for the web with javascript where a lot of times you find yourself checking all different browser.

Some principles for sharing code between .NET platforms

  • Don’t fragment the platform!
  • Code-Portability is not good enough – need to be able to share binaries.
  • Good user-experience requires specific UI suitable to the device. This actually challenge the very idea of sharing UI between platforms.
  • Things that are the same should stay the same. For example, string.Compare should work the same both on web desktop and phone.

Why can’t I just run my app?

  • Some API are very platform specific (System.Windows.Browser)
  • Screen size is very different
  • Input methods are very different
  • Performance characteristics are different

Solution?

Use assembly portability to share Component/Logic.
In .Net 4.0 you can write a class library in Silverlight and use it in .NET 4 application.

Using this technique we can create assemblies that contains most of the logic:

  • Business Logic
  • Validation Code
  • File/Protocol processors
  • Serialization
  • Service Access
  • View Models
  • Authentication Code

Announcing: The Portable Library Project

This project will be available as a preview on H1 2011.
It will be a new class library type, that you can choose the targeted platforms and it will narrow the API you use to the APIs that are common between the targeted platforms.

The DLL that will be produced is a simple Silverlight DLL.

Can We Share Assemblies Today?

Yes! You can create a Silverlight 3 class library project today and have it reference from WPF, Silverlight web application and Silverlight Windows Phone application.
On the last case you will get a warning from Visual Studio but this should work nevertheless.

The downside is that you don’t get the automatic IDE support that minimizes the valid APIs, so you need to be careful not to use APIs that are not available in one of the targeted platforms.

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

PDC 2010: Optimizing Performance for Silverlight Windows Phone 7 Applications

Following is a summary of the session “Optimizing Performance for Silverlight Windows Phone 7 Applications” presented by Oren Nachman, Software Developer at Microsoft, in PDC 2010.

image

This session takes what we have learned in the previous session about Windows Phone 7 to the next level.

Oren shows code snippets that actually make a difference and demonstrates very nicely how you can analyze your app to fins performance pitfalls.

Performance

Silverlight Threading on the Phone

Silverlight for phone has a thread named “compositor thread” that removes responsibility off the UI thread, mainly to handle animations. For example when you create an animation that moves a circle, the first rendering of the circle is done on the UI thread and the composer thread handles moving the circle.

image

Performance Debugging

Performance counters:

  1. Composition Thread Frame Rate: how many frames per second are ticking on compositor thread.
  2. UI Thread Frame Rate: how many per second are ticking on UI thread.
  3. Texture Memory Usage
  4. Surface Counter
  5. Intermediate Surface Counter
  6. Fill Rate Counter

Check this article for recommended values and more details for Windows Phone 7 counters.

ListBox

There is a tradeoff between using the StackPanel vs. using a VirtualizedStackPanel inside the ListBox.

The ListBox in Windows Phone 7 by default uses a VirtualizedStackPanel, so not all elements are loaded at once. This is to avoid loading all the elements into the memory (there is a limit on memory utilization of 90mb).
The problem with this method is that scrolling between the items might get a little jerky since items are being loaded as you scroll.

On the opposite end, you can use StackPanel in the ListBox but then loading takes more time since all the elements are loaded in advance.

Another useful tip is instead of binding to an IList that is ready in advance, bind to an ObservableCollection and add items as you go, while the page is already loaded.

Panorama and Pivot

Several tips when you use the Panorama control or Pivot control:

  • Animations on pages that are not seen are still animating and taking performance down the drain.
  • the Panorama control has no virtualization. That means that all pages in the panorama are loaded at once.
  • Delay load if loading is heavy.
  • If you do lots of binding, it is done on all pages. To fix this split your view models to match your views.
  • Finally, don’t optimize if it works fine!

Networking

Prefer using HttpWebRequest on BackgroundThread over WebClient. Since WebClient always post back to the UI thread.

Limit to 6 parallel requests (this is a system limit).

When using WIFI download large chunks in parallel to get better throughput.

Popup

Popup has minimal hardware acceleration, prefer not to use it. Instead you can use a hidden canvas that is just waiting to show.

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

PDC 2010: Things I Wish I Knew Three Months Ago about Building Windows Phone 7 Applications

Following is a summary of the session “Things I Wish I Knew Three Months Ago about Building Windows Phone 7 Applications” presented by Jaime Rodriguez, Microsoft evangelist, in PDC 2010.

image

The talk is about common windows phone 7 applications and lessons learned from building them.

First Jaime presented Vikas Gupta, mobile engineer of Facebook, that showed the panorama-based Facebook for Windows Phone 7.

Then Jaime presented Leland Rechis, program manager for twitter mobile, that showed the pivot-based Twitter for Windows Phone 7.

Architecture

There is nothing special in a Windows Phone 7 applications. They have UI layer, view-models, models etc..

User Experience

Metro experience

  • Know the phone before you design an application for it. It’s not the same experience as iPhone / android.
  • Learn about Metro UI design for Windows Phone 7.
  • Take the design recommendations as just that, recommendations.

Branding

  • Balance the graphics between the Metro UI design and the branding.
  • Custom themes requires lot’s of tedious work. You must test all your themes with both of the windows phone themes (light and dark).
  • If you’re doing custom theming, hide the system tray because it cannot be themed.

Application Bar

  • The application bar actions should be page level actions only.
  • Specifically, context based actions should not be on the application bar, use the content menu for them.
  • Remember the application bar is always on top, event above the SIP (Soft Input Panel, AKA keyboard).

Orientation

  • Design your UI for 3+ screens: Portrait, Landscape and Landscape with HW keyboard

Navigation

  • Some pages should not be inserted to the page stack, like login page.
    Use popup & Overlays to avoid a new page.

Page Transitions

Demoed by Will Danford, lead developer of the Facebook mobile.

Why use it?

1. Make your application more attractive (having a fluid flow).

2. Carry context from one page to the next.

3. Increase perceived performance of your application.

Types of transitions:

1. Continuum animation – show the context of where you are going.

2. Turn style – used for task switching, moving between functionality different screens.

3. Popup style - used for transient screens.

Tips on transitions:

1. Make sure you need it!

2. Show the next page as quickly as possible. Data-bind only after page appears.

3. Use brief animation (up to 350ms).

4. Wrap the navigation service to avoid multiple navigation by anxious users..

5. To implement transitions subclass PhoneApplicationPage (then cancel navigation, show animation and do navigation).

Phone Stuff

Tombstoning

Second most important concept of the phone (first is Metro design).
Tombstoning dominates the perceptions of performance.

Some tips on tombstoning:

  • Only save what you need.
  • Use binary serialization instead of XML-based serialization.

Using GeoCoordinateWatcher

  • Warm it up first, get the location before you need it.
  • Singleton. You don’t need more than one
  • Never dispose

Using Bing Maps

  • Consider touch interactions. Adding the map control into a pivot control doesn't works well, since both controls compete for touch interactions.

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

PDC 2010: The Future of C# and Visual Basic

Following is a summary of the session “The Future of C# and Visual Basic” presented by Anders Hejlsberg, lead architect of the C# programming language, in PDC 2010.

History

Before talking about the future, Anders starts with a review of C# and VB.NET history.
Anders identifies three major trends over the passing decade:

  • Declarative – concentrates on “What do you want do?” instead of “How you want to do it?”
  • Dynamic – allowing more fluent style of programming using dynamic languages like IronPyton.
  • Concurrent – leveraging multi-core and multi-pc processing.

Note that for the rest of the talk Anders relates to C# only, but Visual Basic is paired with C# in all that matter.

When you take a look at the C# language constructs (not .NET Framework), there is nothing specific for concurrent programming other than a simple “lock” statement.

Well, this is going to change on the next version of c# with the addition of Asynchronous Programming to the language.

image

Today’s applications are increasingly connected to other services. This induce more latency, UI responsiveness problems and scalability issues.

Asynchrony in a Nutshell

On a synchronous operation you call a function and then wait for it to return the result.

On an asynchronous operation you call a function, give it an OnCompleted callback and continue to do other things. When the result is ready the OnCompleted callback is called.

So using asynchronous programming we gain:

  • UI responsiveness: since the the UI thread is free do handle user interaction
  • Server scalability: threads can be reused for other requests.

Presenting Visual Studio Async CTP

The Visual Studio Async CTP (Community Technical Preview) adds to C# two new keywords: await and async. These keywords use heavily the class Task<T> which was presented in .NET 4.0.
These keywords are used as syntactic sugar for making asynchronous programming easy. A good comparison is the the yield keyword which was introduced back in .NET 2.0 to allow easy implementation of iterators.

Task<T> is an ongoing operation that will eventually return a value of type T.

The await operator works on Task<T> instance and causes an asynchronous wait for the value of the task. Using the await operator can be done only in functions declared with the async operator.

The async modifier is used on a function declaration to indicate this is an asynchronous method.
This means that the function does some of its processing asynchronously.
The return value of an asynchronous method must be either void, Task or Task<T>.

Note: as a convention, the name of asynchronous methods that returns Task or Task<T> should end with “Async”. (e.g. GetDataAsync)

When you run an asynchronous method, it actually runs synchronously until the first encounter of await operator. At this time it returns control to the caller while asynchronously waiting for the remaining of the function.

In his talk Anders show how using the new keywords, handling errors is done by simply adding a try catch block, same as with synchronous method calls.

Why Not Use Multiple Threads?

Most of the problems asynchronous programming solves can also be solved using multi-threading, so why not?

The problem with multi-threading programming is that it brings to the table its own set of problems and overhead. Multi-threading demands that you handle synchronization to shared resources, which has we all know can be a pain.
In addition, multi-threading cause context-switching overhead.

So when should we use multi-threading?
Only on CPU-bound operations where you really need to use multiple CPUs to cut processing time.

Status of Compiler Services Project

Although no official announcements were made on this subject, Anders did show a demo that uses the current version of this project. In his demo he showed an extension to visual studio that uses the compiler services to copy code in C# to the clipboard and paste it as VB.NET code, the extension uses the compiler generated syntax tree for the code to do the conversion accurately.

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

PDC 2010: My Schedule For Day 2

Following is my schedule for day 2 of PDC 2010:

Day 2, 09:00-10:00
Session
: Building High Performance HTML 5 Sites with IE 9 by Jason Weber
Description: Learn about what actually drives performance across the web and how you can make your sites faster. See how Internet Explorer has been redesigned from the ground up to take advantage of modern PC hardware, and how GPU powered graphics, compiled JavaScript, and HTML5 are revolutionizing how developers think about the web.

Day 2, 10:15-11:15
Session
: Microsoft Visual Studio IntelliTrace, Test Impact Analysis and Tier Interaction Profiling by Justin Marks
Description: As applications become more complex and pressures to decrease costs increase, we need tools to facilitate reducing the turn-around time for testers and developers to find and fix bugs. In this session, we’ll show how new diagnostics capabilities such as IntelliTrace and Test Impact Analysis can help us get rid of those pesky “no repro” scenarios that routinely plague developer / tester interactions. We will dive deep into some of the more advanced scenarios that IntelliTrace supports such as debugging user code failures, tweaking the settings of IntelliTrace to customize collection, command line collection, and debugging failures in Azure applications. We’ll then go into how you can gain confidence of quality before checking in by helping developers run the right automated tests based on Test Impact Analysis and ensuring a performant end-user scenario using multi-tier performance analysis.

Day 2, 11:30-12:30
Session
: Inside Windows Azure by Mark Russinovich
Description: Join Mark Russinovich, now working on Windows Azure, for an under the hood tour of the internals of Microsoft’s new cloud OS. Topics will include datacenter architecture, cloud OS architecture, and what goes on behind the scenes when you deploy a service, a machine fails or comes online and a role fails.

Day 2, 14:00-15:00
Session
: Real-World Analysis and Optimization of XNA Framework Games on Windows Phone 7 by Jeff Petkau
Description: Good code design, performance tips, and a solid understanding of the platform are all essential to game development. Learn how to use the Microsoft’s Advanced Technology Group's (ATG) battle-tested techniques to find and fix performance-killing issues in Windows Phone 7 XNA Framework game code. Also, hear about real-world analysis and optimization of XNA Framework games on Windows Phone 7.

Day 2, 15:00-16:15
Session
: Taking Advantage of Pinned Sites with Internet Explorer 9 and Windows 7 by Israel Hilerio
Description: Internet Explorer 9 allows developers to more tightly integrate their websites with the Windows 7 task bar and start menu. With Pinned Sites, you can add a website to the start menu, define Jump List tasks, create custom Jump List items, provide visual notifications on the task bar with icon overlays and even add custom thumbbar buttons on the default thumbnail preview. See how this functionality works without any markup changes from you, and then dive deep into enhancements you can add without changing your sites layout! This session will provide best practices and guidance from Pinned Site that have already been built. We’ll see how this is done through the IE F12 developer tools.

That’s it for now,
Arik Poznanski

kick it on DotNetKicks.com Shout it

PDC 2010: Free Phone for PDC Participants

Following are some images and details on the free Windows Phone 7 that all PDC participants got.

IMG_20101028_231036IMG_20101028_231348


Some of the LG-E900 specifications:

  • 3.8” WVGA Display
  • 5 Megapixel camera with flash
  • 16GB storage
  • Touch screen
  • Connectivity: 802.11b/g/n, Bluetooth and A-GPS
  • Windows Phone 7 OS
  • screen size: 480x800

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

PDC 2010, Day 1: Keynotes: Windows Azure

Windows Azure and PaaS

IMG_20101028_100635_thumb[1]

President of Microsoft's Server and Tools Business, Bob Muglia, comes to the stage.
He starts by reviewing the different types of cloud computing:

  • Software as a Service (SaaS)
  • Platform as a Service (PaaS)
  • Infrastructure as a Service (IaaS)

Then he dives in to the the advantages of PaaS vs. todays platforms:

  1. In today’s platform you must deal with server, VM, network, storage and your application. Whereas in PaaS you only think of the application (no infrastructure).
  2. In today’s platform you must take care of your servers, apply patches, service releases, new upgrades and their possible consequence on your application. Whereas in PaaS this is all done for you and Microsoft will stay compatible when upgrading their service infrastructure.
  3. In today’s platform you need to write lot’s of code for compose your helper services yourself to make them work. Whereas in PaaS, you got a list of existing services provided by Microsoft that you can use.
  4. In today’s platform every problem has solutions that are different in many ways: network topology, operating system, storage, etc.. Whereas in PaaS the solution is always standardized, at lease from these perspectives.
  5. In today’s platform you need to plan your solution for peak load. Whereas in PaaS you can scale on-demand.
  6. In today’s platform you build the application to avoid & recover from failure. Whereas in PaaS you build your application to expect and withheld failure.

Windows Azure is the operating system for PaaS.It manages the underling hardware and provides services.

Some More Windows Azure News

All the services that are now available in the cloud will be made available to the private cloud.

Microsoft is making their cloud open to anyone. That means that java is a first class citizen on Windows Azure. You can also build Windows Azure applications using eclipse. Support for dynamic languages like PHP and Ruby exists.

Now there is a showcase by Chris Ford from Pixar Animation Studios that shows how they use Microsoft’s cloud and integrate it into their main, award-winning, rendering engine.

The reason you need cloud computing for the render process in the first place is that rendering takes lot’s of CPU processing. For example, if the movie Toy Story 3 was rendered on a single CPU, it would take approximately 277 years to finish the rendering.

Pixar chose Windows Azure for its cloud solution for the following reasons:

  • Scalability – They need lot’s of computers for doing this type of cloud.
  • Sustainability – They need the solution to be available two years later.. not every company can do such promises.
  • It works – Microsoft cloud simply works.

More Applications to the Cloud

Bob Announce:

  1. Windows Azure Virtual Machine Role – Allows to easily move a Windows Server 2008 R2 image into the cloud.
  2. Server Application Virtualization – Wraps the application and deploy to azure

New features in the coming version of Windows Azure

  • Extra small instance
  • Remote Desktop
  • Full IIS support
  • Virtual Network
  • Multiple administrators

Now came Mark Russinovitch to present a demo that uses some of these applications. Mark shows how to use the new Windows Azure management console and how to customize installation of a role to the machine.

New TFS

Bob Muglia announce that next year Microsoft will provide TFS as a service.
The demo is presented by Brian Harry which showed us that basically, after you configure your account over the web, the user gets the same UX like with the regular TFS and it also includes support for continues integration over the cloud, etc.

New and Updated Services

The following services are either new or updated:

Windows Azure AppFabric:

  • Access Control Service
  • Caching
  • Service Bus

SQL Azure

  • Reporting
  • DataCenter

We saw a demo by Don Box and Jonathan Carter that uses some of these new services.

Also announcing: Windows Azure MarketPlace which includes DataCenter, and a Composition Service that supports WF.

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

PDC 2010, Day 1: Keynotes: Windows Phone 7

Windows Phone 7

Make sure you check the Windows Phone 7 Ad which is soon to be available in he US.

At this moment Steve announced that all PDC 2010 participants will receive their own personal Windows Phone 7! Today.

IMG_20101028_092652_thumb[1]

Now Scott Guthrie comes to talk about Windows Phone 7.
Next, Brandon Watson presents us a demo of several Windows Phone 7 applications, including: Bejeweled, Facebook and Amazon Kindle for Windows Phone 7.

After the demo, Scott shows how to quickly develop applications for the Windows Phone 7. This can be done entirely free using: Visual Studio 2010 Express and Windows Phone 7 Developer Tools, which can be downloaded here.

(Small) Announcement: Today Microsoft is shipping a new OData client library for Windows Phone 7.

Now Scott shows another demo of building a panorama based application that gets his data from eBay using the new OData library client.

Another (small) Announcement: Profiling tools for Windows Phone 7 will be available soon. The profiler is using instrumentation for collecting accurate information about: Frame rate, CPU usage and storyboards and displays it on a timeline.

Scott shows a demo of using the new profiling tools

Steve Ballmer returns to the stage and promises yet another gift for PDC 2010 participants: a free registration to the Windows Phone 7 Marketplace to submit our own applications (costs 99$).

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

PDC 2010, Day 1: Keynotes: IE9 + HTML5

Here is a summary of the major issues presented by the CEO of MSFT, Steve Ballmer, and Bob Muglia in PDC 2010 keynotes.

You can find the most impressive ones under www.microsoft.com/news

waiting for keynotes

In the image, waiting for the keynotes to start.

First, some PDC statistics, according to Steve, there is approximately 30,000 live viewers of the PDC keynotes, including the local sites around the world. Around 1,000 are in Redmond. I’m one of them Smile.

Internet Explorer 9 and HTML 5

Steve talked about the move to smarter devices (PC, Phone, Xbox) and the evolution of cloud applications and services, and the fact that “HTML 5 is the glue for all frontend and backend”.and the fact that “HTML 5 is the glue for all front-ends and back-ends”.

image

Steve mentioned some statistics about Windows 7, over 350,000,000 new PC sold in the last 12 month, and 240,000,000 Windows 7 licenses sold.

The hardware is starting to catch-up, many devices have touch support, and this number will just continue to go up.

Internet explorer 9 latest version has some unique features, including:

  • Great support for HTML 5
  • Giving improved user experience of a site running on a windows based-machine.
    Quote: “Try to make the web feel like native application”

On the 6 weeks of beta testing IE9, it was downloaded 10,000,000 times. That’s the most downloads ever for a beta of internet explorer. And probably any browser beta for that matter.

Corporate vice president in charge of the Internet Explorer team, Dean Hachamovitch was brought to the stage to show a demo of IE9 features including: Hardware acceleration of video and animation, HTML 5, performance comparison with Google Chrome and Integration with Windows 7 user tasks.

You can download the latest version (Platform Preview 6) of Internet Explorer 9 beta here and find the code for the demos in www.ietestdrive.com.

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

PDC 2010: Day 0

Today I came to Microsoft campus early to take the new Silverlight 4 beta exam.
If you attend the PDC, know the material and have 4 hours of free time, I suggest you get by building 40 and have the exam. To register, follow the instructions in this post and its comments.

After the exam enjoyed the nice weather and walked thru Microsoft campus..

מיקרוסופט

Later this day I’ve attended the welcome reception which was quite awesome with lot’s of interesting people, tasty food and futuristic games (Kinect). By futuristic I mean, to be released in US on November 4, 2010.

Now I’m planning my schedule for tomorrow. Will see how it turns out in real life. Remember: Life is what happens to you while you're busy making other plans.

Day 1, 09:00-11:00
PDC10 keynotes by Steve Ballmer and Bob Muglia

Day 1, 11:30-12:30
Session
: The Future of C# and Visual Basic by Anders Hejlsberg
Description: Come hear technical fellow Anders Hejlsberg describe the roadmap for C# and Visual Basic in vNext and beyond.
See how these languages are evolving to address developer needs, and get an update on projects underway.

Day 1, 14:00-15:00
Session
: Things I Wish I Knew Three Months Ago about Building Windows Phone 7 Applications by Jaime Rodriguez
Description: The Windows Phone clients for Twitter and Facebook are two new, native-looking Windows Phone applications. Come hear about all the lessons learned while developing these applications. Learn insights on UX as well as development/architecture patterns for building great, well-behaved, native-looking Windows Phone 7 apps.

Day 1, 15:15-16:15
Session
: Optimizing Performance for Silverlight WP7 Apps by Oren Nachman
Description: Hear about the key tips, tricks and common mistakes that were learned by analyzing several real world applications. See demos of how real apps are debugged. Also learn how to write world class applications with animations running at 60fps.

Day 1, 16:30-17:30
Session
: 3-Screen Coding: Sharing code between Windows .. by Shawn Burke
Description: Get a preview of upcoming Visual Studio features that will allow you to share code between Microsoft .NET platforms. You’ll learn how to structure applications to maximize the amount of shared code, how to write an app that’s used across Silverlight Desktop and Windows Phone, and how to build business logic and helper functions that work across all 3 Screens plus the cloud.

I can’t wait!!

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

PDC 2010, Here I Come!

I’ve got a ticket to PDC 2010!

I wanted to go since I’ve heard about it this year, but by the time I tried to register, all tickets were:

SOLD OUT

Just when I gave up on this conference (actually two weeks after I gave up), I got phone call saying I got a ticket..

Before I continue, I want to thank all those people at SELA and Microsoft who helped in getting me this ticket, you know who you are.. thank you.

So today my flight was booked and tomorrow night I’m leaving.
I don’t know yet where I will stay, hopefully this will get resolved by the time I arrive..

If you’re in Redmond this week and want to talk, don’t hesitate to contact me.
Incidentally, I’ve figured it’s about time I get a twitter account: @arikpoz

That’s it for now,
Arik Poznanski.

Windows Ribbon for WinForms v2.5 Released – New Events Mechanism

The Windows Ribbon for WinForms is a managed wrapper around Windows Ribbon Framework, a free ribbon control that Microsoft provides in Windows 7 and Vista.
More details on this project can be found in the project site: windowsribbon.codeplex.com .

I’ve just released another update to the project.

Note: this release contains breaking changes, only take it if you are starting a new project, or you don’t mind the needed updates to your code.

Basically I’ve changed how events are exposed in the library, made it a little more .NET friendly.

The benefits of these changes are:

  • You now get the control which generated the event as the sender of the event.
    For example, this allows registering the same callback function to different buttons and have the ability to know which button raised the event.
  • You can now use the Windows Ribbon for WinForms library in languages that can work only with proper .NET event handlers. The first request for this feature was from someone who wanted to use it in Progress ABL… There is a world beyond C#, C++ and VB.NET…

How to upgrade existing code?

If you already have code that uses previous versions of the project, follow these guidelines to do the upgrade.

Upgrading C# Code

The event names and signatures changed, thus, you need to change code like this:

_buttonNew.OnExecute += new OnExecuteEventHandler(_buttonNew_OnExecute);

_richFont.OnPreview += new OnPreviewEventHandler(_richFont_OnPreview);

_richFont.OnCancelPreview += new OnCancelPreviewEventHandler(_richFont_OnCancelPreview);

Into code like this:

_buttonNew.ExecuteEvent += new EventHandler<ExecuteEventArgs>(_buttonNew_OnExecute);

_richFont.PreviewEvent += new EventHandler<ExecuteEventArgs>(_richFont_OnPreview);

_richFont.CancelPreviewEvent += new EventHandler<ExecuteEventArgs>(_richFont_OnCancelPreview);

And change the method signatures from this:

void _buttonNew_OnExecute(PropertyKeyRef key, PropVariantRef currentValue, IUISimplePropertySet commandExecutionProperties)

To this:

void _buttonNew_OnExecute(object sender, ExecuteEventArgs e)

Note that the ExecuteEventArgs class holds the data that was previously passed to the execute method directly.

Upgrading VB.NET Code

The event names and signatures changed, thus, you need to change code like this:

AddHandler _buttonNew.OnExecute, AddressOf _buttonNew_OnExecute

AddHandler _richFont.OnPreview, AddressOf _richFont_OnPreview

AddHandler _richFont.OnCancelPreview, AddressOf _richFont_OnCancelPreview

Into code like this:

AddHandler _buttonNew.ExecuteEvent, AddressOf _buttonNew_ExecuteEvent

AddHandler _richFont.PreviewEvent, AddressOf _richFont_PreviewEvent

AddHandler _richFont.CancelPreviewEvent, AddressOf _richFont_CancelPreviewEvent

And change the method signatures from this:

Private Sub _buttonNew_OnExecute(ByVal key As PropertyKeyRef, ByVal currentValue As PropVariantRef, ByVal commandExecutionProperties As IUISimplePropertySet)

To this:

Private Sub _buttonNew_ExecuteEvent(ByVal sender As Object, ByVal e As ExecuteEventArgs)

Note that the ExecuteEventArgs class holds the data that was previously passed to the execute method directly.

That’s it for now,
Arik Poznanski.

Order in Chaos: .NET Collections

This is a review of the current available collection types in .NET Framework 4.0

Note that I don’t plan to explain all the history of the different collection. If a class is obsolete, that is enough information.

The intention is to use this post as a reference when you need to decide which type of collection you should use.

Also, I’m not going to give the complexity of each function. You can find such information in the relevant class documentation on MSDN.
Anyway, you can deduce it yourself, since this it quite common knowledge, for example, an array-based list has O(1) for adding to the end and O(n) for adding in the middle. Just think about it.

One final note before we begin, I'm skipping the special collections, mainly the synchronized and concurrent ones.

The review will have have the following convention: Class Name, Namespace, Description and Bottom Line.

For example: 

Class name: Array
Namespace: System
Description: The base class of all the arrays in the .NET framework.
Bottom line: Very basic type, but sometimes this is all you need.

The Old Collections

Common Old Collections

Class name: ArrayList
Namespace: System.Collection
Description: List of objects, internally uses an array which resizes dynamically.
Bottom line: Use List<T> instead.

Class name: Stack
Namespace: System.Collection
Description: Represents a last-in-first-out (LIFO) collection of objects. Implemented as a circular array, sized dynamically.
Bottom line: Use Stack<T> instead.

Class name: Queue
Namespace: System.Collection
Description: Represents a first-in-first-out (FIFO) collection of objects.
Implemented as a circular array, sized dynamically.
Bottom line: Use Queue<T> instead.

Class name: Hashtable
Namespace: System.Collection
Description: Represents a mapping between a key and a value using a hash table.
Bottom line: Use Dictionary<T> instead.

Less Common Old Collections

Class name: CollectionBase
Namespace: System.Collection
Description: A base class intended to be used in implementations of strongly typed collections.
Bottom line: Use Collection<T> instead.

Class name: ReadOnlyCollectionBase
Namespace: System.Collection
Description: A base class intended to be used in implementation of strongly typed read-only collections.
Bottom line: Use ReadOnlyCollection<T> instead.

Class name: SortedList
Namespace: System.Collection
Description: A list of key-value pairs, sorted by keys, can be accessed using key or index.
Bottom line: Use SortedList<TKey,TValue> instead.

Class name: ListDictionary
Namespace: System.Collections.Specialized
Description: Like Hashtable, but internally uses a singly linked list. Recommended only when the number of items in the collection is 10 or less.
Bottom line: IMHO, this optimization doesn’t worth my time. Use Dictionary<T> instead.

Class name: HybridDictionary
Namespace: System.Collections.Specialized
Description: Uses ListDictionary when the collection is small and switches to Hashtable when the collections gets large.
Bottom line: If this is so great it should have been Hashtable default implementation. Use Dictionary<T> instead.

Class name: OrderedDictionary
Namespace: System.Collections.Specialized
Description: A list of key-value pairs, can be accessed using key or index.
Bottom line: Use SortedList<TKey, TValue> instead.

Class name: StringCollection
Namespace: System.Collections.Specialized
Description: A collection of strings.
Bottom line: Use List<string> instead.

Class name: StringDictionary
Namespace: System.Collections.Specialized
Description: A hash table with both keys and values as strings.
Bottom line: Use Dictionary<string,string> instead.

Still Useful

Class name: BitArray
Namespace: System.Collection
Description: An efficient array of bit values, uses only 1 bit for each flag.
Bottom line: Only if you have tons of flags.

Class name: BitVector32
Namespace: System.Collections.Specialized
Description: Like BitArray but more performant and limited to 32 bits
Bottom line: Only when a plain old Enum doesn’t answer your needs. 

The New Collections

Common New Collections

Class name: List<T>
Namespace: System.Collections.Generic
Description: Generic list of T, internally uses an array which resizes dynamically.
Bottom line: Your first choice when in need of a simple dynamic collection.

Class name: LinkedList<T>
Namespace: System.Collections.Generic
Description: Generic list of T, internally uses doubly linked nodes to store the data.
Bottom line: Same as List<T> only with different performance in some of the operations.

Class name: Stack<T>
Namespace: System.Collections.Generic
Description: Generic last-in-first-out (LIFO) collection.
Bottom line: Your first choice when in need of a stack.

Class name: Queue<T>
Namespace: System.Collections.Generic
Description: Generic first-in-first-out (FIFO) collection.
Bottom line: Your first choice when in need of a queue.

Class name: Dictionary<TKey, TValue>
Namespace: System.Collections.Generic
Description: Represents a mapping between a key and a value using a generic hash table.
Bottom line: If I had to select only one collection, this would be it. The most useful among the different collections.

Less Common New Collections

Class name: SortedDictionary<TKey, TValue>
Namespace: System.Collections.Generic
Description: Represents a collection of key/value pairs that are sorted by the key. Similar to SortedList<TKey, TValue> only has some different performance in some of the operations.
Bottom line: Like a dictionary, only sorted. Only when you need exactly that.

Class name: SortedList<TKey, TValue>
Namespace: System.Collections.Generic
Description: Same as SortedDictionary<TKey, TValue> only with different performance for some of the operations.
Bottom line: the twin browser of SortedDictionary<TKey, TValue>

Class name: HashSet<T>
Namespace: System.Collections.Generic
Description: Generic set of values, i.e. a collection with no duplicates and in no particular order.
Bottom line: This class still searches his place in the world. Use it when it is exactly what you need.

Class name: SortedSet<T>
Namespace: System.Collections.Generic
Description: Generic set of values, that maintains the values order.
Bottom line: I guess I can find a scenario for this one..

Class name: Collection<T>
Namespace: System.Collections.ObjectModel
Description: A base class to be used with custom strongly typed collections.
Bottom line: If you want a collection that is extendable, e.g. lets you customize add / remove operations, you should inherit from Collection<T>. If all you need is a strongly typed collection, use List<T> which provides some additional methods but lacks the extensibility points.

Class name: ReadOnlyCollection<T>
Namespace: System.Collections.ObjectModel
Description: A base class to be used with custom strongly typed read-only collections. Bottom line: The read-only counterpart of Collection<T>

Class name: ObservableCollection<T>
Namespace: System.Collections.ObjectModel
Description: Represents a collection that provides notifications when items get added or removed.
Bottom line: Very useful in WPF.

Class name: ReadOnlyObservableCollection<T>
Namespace: System.Collections.ObjectModel
Description: Represents a read-only ObservableCollection<T>
Bottom line: Useful when you want to protect your collection without losing the observable property.

That’s it for now,
Arik Poznanski.