Scott Hanselman

iPad, Surface, Ultrabook: Are we there yet?

January 5, '13 Comments [53] Posted in Reviews
Sponsored By

imageDisclaimer: I work for Microsoft in Azure doing open source for the web. I have never worked for the Windows group. I've been blogging here for a decade and I stand on my reputation for being fair and impartial to the best of my abilities.

One day, someone will make the perfect computing device. Or will they? I'm starting to think it's just not possible.

At this point, in 2013, we all want something that is/has:

  • Speed. Note that I didn't say power. I think the days of chasing the all mighty gigahertz is over. I don't care if I have a 3GHz processor or a quad-core whatever. I want apps to launch in an a second or so.
  • Light. I spent years carrying around a 10 pound laptop and calling it light. Before that it was 17 pounds and I called it light. Now I'm carrying a 3 pound Ultrabook and thinking that the power supply is heavy. Whatever is next, it needs to be <= 3 pounds.
  • Size. For a number of years there have been 15" and 17" laptops with huge screens. I believe this is because a 15" or larger laptop was the only way to get a great screen resolution. Now that we can get 1080p resolution (or larger!) on a 13" or 11" screen there's less reason to go large.
  • Touch. Everything needs touch. Reaching out and touching an icon is more intuitive than using a mouse, touchpad or that weird little Thinkpad eraser head. You eraserhead people are weird.
    • "Every laptop should (and will) have a touch screen in a year. Mark my words. This nonsense about how your arm will hurt assumes that you're only using it. A touchscreen is complementary not primary."
  • Quality. Plastic crap is plastic crap. We care about our devices these days and we use them everywhere. Apple proved this with its excellent engineering and aluminum construction. Microsoft validated this and pointed out to OEMs with the engineering work put into the Surface. Microsoft has long made awesome keyboards and mice. I'm glad to see more quality hardware coming out.
  • Keyboard. Now, I didn't say "integrated keyboard" or "fancy touch cover keyboard." I just mean keyboard. I would expand this even more to say "I need a keyboard when I need one and I need it to work well." When I need a keyboard, I usually need it for either a short email OR a long document. For short emails or tweets an on-screen keyboard works but sometimes I do need to write for a dozen pages and I want that experience to be comfortable.
  • Integrated. Everything should "just work." That means touch scrolling without thinking of drivers, automatic updates without thinking, apps that support all my services (Gmail, Hotmail, LinkedIn, etc.)
  • Ecosystem. The apps that I use. Twitter, Facebook, Instagram, Trello, Words with Friends, etc. I wrote about this in my post  "I can't even think about switching phones without these apps." Once you're invested in an ecosystem, the ecosystem itself is a kind of gravity that keeps you on that platform. If I had 2 apps I cared about, switching phones or platforms isn't a big deal. Once I have 20, I need those 20 to exist on new platform - and be awesome - before I switch.

Those are the characteristics that we can all agree on. Now, let's apply those to different needs and work styles.

Consumption vs. Production

SkyDrive integration in Windows 8 RTThis is an axis you see a lot, most often as a way for folks to say that the iPad is a device for reading/getting/consuming and not making/creating/producing. This may have been the case early with the iPad on but it's less valid now.

If you're a writing using an iPad, there are a number of excellent keyboards and 3rd party keyboard covers for the iPad. Personally, I've paired an Apple Wireless Keyboard to my iPad and written on it quite happily. The real issue with producing on the iPad is its lack of a shared file system and most application's mediocre offline integration with services like Dropbox. There are a number of Markdown editors like IA Writer that get close, but none quite achieve the dream: get on a plane, write a bunch offline with a great word processor, get off the plane and sync to Dropbox. We are always forced to "think" about where thing are. Even in Pages - which is a fantastic technical achievement - there's still a constant "copy from WebDav" and "Copy to iTunes." Dealing with iPad documents is such a hassle, in fact, sometimes just emailing the thing is easiest. This is something that COULD be solved, I'm sure, if there was the will to do it right. If you buy into using only iCloud, the experience is better, of course. QuickOffice Pro HD also gets close, but the inability to use one app for storage and another for editing is a consistent problem.

If you're a coder, you can use an iPad or Surface to remote into a larger machine via Remote Desktop or VNC or SSH (with an app like Prompt from Panic) but then you've turned your modern machine into a terminal. That's fine, but it doesn't really take advantage of its capabilities.

The Surface RT has a similar but slightly different problem. There IS a clear file system and it's accessible to you, even from "modern" apps. However, there's no DropBox application (yet) although there's word that an app has been submitted to the store. I'd like to see it in the standard file dialogs like this screenshot. I'd like to see SkyDrive, DropBox, Google Docs, etc. all be available and smart. SkyDrive is well integrated into Office and standard dialogs. I hope others can be. We shall see!

UPDATE: The DropBox app has just arrived in the Windows Store and YES you can open and save files to it from any applications! Get the Dropbox app here.

An Ultrabook (or a MacBook), since it's a full computer, doesn't have any of these restrictions. You can do whatever you like however you like with whatever programs you want whether they are "in the store" or not.

This brings me to the next axis...

Keyboard or no Keyboard or Keyboard in a Cover

Lenovo Yoga 13 ConvertibleTo get "real" work done, until voice recognition reaches 99% or subvocalization becomes reality, you'll need a keyboard. The touch keyboard on the iPad is excellent, really. There's some amazing dynamic resizing of the buttons as well as some smarts when the keyboard is split in two. However, tapping on a screen hurts my bones after a few pages. It's just not as comfortable as a keyboard with "throw" where the keys give under pressure. Not to mention an on-screen keyboard takes up half the screen.

The Surface RT's claim to fame is the Touch Cover. It's a magnetic cover not unlike the iPad one except it doesn't fold. There's an integrated keyboard within the felt cover. You really have to try it to decide if it's for you. It's not for me. I have tried to type on it for weeks now and I've given up. I am only about 80% of my regular speed and it consistently misses my touches. This need to double-touch to make sure a key is hit has been the deal breaker for me, preventing me from getting work done with the Surface.

I went and bought a Type Cover. This is the magnetic Surface cover with an actual keyboard with keys that move. This is a fantastic keyboard rivaling that of my ThinkPad. It's super thin but it's a few millimeters thicker than the Touch Cover so I'm a tiny bit sad. Also, when you fold the Type Cover back, the keys are facing outward so you can feel them when you use the Surface. It bothered me for a bit but then I just decided to get over it. It remains to be seen if others will, but I can attest to the fact that the Type Cover is a killer keyboard, not unlike my Apple Wireless Keyboard.

In fact, if Apple would make an iPad keyboard that didn't have the round battery area that sticks up so much, they'd have a great little combo. I tried carrying an iPad and the Apple Wireless Keyboard around for a while but but the resulting thickness is greater than - and less useful than - a MacBook Air or Ultrabook alone.

I love the idea of a no-compromises "convertible." A full keyboard that takes up only the space required and then goes away as much as possible when I just want a tablet for touch or movies. The Lenovo Yoga (or some MacBook Air that doesn't yet exist but has a touch screen and folds) approaches this perfection. The new Samsung Chronos Ultrabook Series 7 doesn't fold but includes a touchscreen and looks pretty awesome as well.

Speed

iPad AppsI don't know what the speed of the Surface or my iPad but I don't care. Knowing the processor speed doesn't tell me if apps load in a second. Some do on my iPad. Some do on my Surface. All the important ones (Mail, Calendar, etc) load on my iPad in a second. It unlocks instantly. On the Surface they almost load in a second. Sometimes it's instant, sometimes it's 3 seconds. I don't know why it differs. Perhaps sometimes the apps are "warm." I think the Surface RT could do for some app-specific speed optimizations because some apps (Maps) take as long as 5 seconds to load which, in my mind, isn't acceptable for something classified as a "tablet." I expect instant from a tablet.

Here's where things get interesting. Are the expectations that different from a tablet vs. a laptop? We seem to be more patient with our laptops. I expect basically everything except Gameloft games to load instantly on my iPad. Loading in 5 seconds? Time to Force Quit you because something's taking too long.

This expectation of speed started with the original PalmPilot. I wrote apps for the PalmPilot - one very successful - and they always told their developers "our platform has no concept of a wait cursor. Everything must be instantaneous." That perception persists today. You touch, it jumps. Fast.

This is where the Surface straddles two realities. It's Windows 8. A different version in that it only runs the included Microsoft Office desktop apps, recompiled for ARM processors, and apps from the Windows Store. I haven't had any speed issues to speak of with apps in the Windows Store. The only app that has felt "pokey" is the overloaded default Mail application.

In fact, it's only my Ultrabook (given it's a full i7 processor) that has no issues with speed. However, it does have a fan that kicks on while the Surface and iPad run silent.

Laptops vs. Tablets

For me, the Surface's greatest strength and confusing weakness is that the Surface sometimes looks like a laptop. It has a great keyboard in the Type Cover so I keep having laptop expectations. The Surface wants to be held in landscape - not vertically like an iPad. Because I want it to be a great little laptop I keep being disappointed that is isn't one. I actually removed the cover a number of times to try to force myself to use the Surface as a Tablet. In this mode, as a largely consumption-focused device, the Surface shines in ways my iPad doesn't, mostly because of two things: Its 16:9 screen ratio and the ability to really multitask two apps at once.

The screenshots below have be running Hulu and looking at my calendar. I've got Hulu on the right in the first screen, with the calendar big. Notice the Hulu app knows this and makes great use of the space when it's small. Same thing when I switch them with Hulu Large. I get a different but adaptive view of the calendar. This is a great example of the Surface (and Windows 8) shining as a Tablet. I've even considered rooting my iPad to get this kind of Multitasking. I use the iPad gestures and task switching a lot, but sometimes you just want your video playing while you do other stuff.

Surface running Hulu and my Calendar   Surface running Hulu large and my Calendar small

Size

Surface, iPad and UltrabookThis is such a relative thing. I took the boys to the Apple Store to check out an iPad Mini. They were ALL over it. They have iPod touches and have used the iPad, but you guessed it, the iPods are squinty and the iPad is pretty big. The iPad Mini (and most 7" tablets in general including the Kindle Fire HD and slightly larger tablets like the dead (and rooted) HP TouchPad running Android.

My wife, on the other hand, currently has a 15" Dell Laptop that she likes just fine. It's about 5 years old and runs Word and Excel and Gmail and looks at pictures. She has no complaints. She's written thousands of papers on it and it's currently seeing her through a third advanced degree. She uses her iPad for Words with Friends. For her, it's literally a Words With Friends tablet, and that's cool. I showed her the Surface and told her it was "Windows, except you can only run Office and apps from The Store." She wanted to see what apps were in the store, got Bejeweled and Netflix and was happy. She then proceeded to bang out a paper using Word. I warned her she couldn't install Quicken but she said "all my apps are on the web anyway. It does Gmail, right?" So right there, Spouse Acceptance Factor (SAF or "WAF") handled. Funny thing is, she is confused her old laptop is huge now. She's clearly a good candidate for either a Surface or something in the 11" to 13" range, perhaps an Ultrabook.

Me, I keep coming back to my Ultrabook. It's 1600x900 resolution is nice, although I'd prefer 1080p. Perhaps the Surface Pro or a new Samsung would do. It's full Windows, plus it has a touch screen. However, it's kind of a lousy tablet as I can't flip it around or yank off its keyboard.

Ecosystem

surfaceipadultrabookThe Windows Store is getting considerably bigger even in the last few months I've been watching it. There's 13 Markdown editors for example, if the number of Markdown editors can be any evidence of an App Store's health, but half are churned out garbage as is common in the early days of App Stores. As a user I'm less interested in if there's 20,000 apps or 100,000 apps. Those numbers are less meaningful to me that 100 or 200 apps that I will use and love and tell friends about.

According to the Windows Store when I select "Your Apps," I've downloaded and installed 198 apps.  I have 55 pinned to my start screen and 15 are games. I'd tell my friends about all these apps and others. I'm comforted, however, as there are apps to write code with syntax highlighting so an Emacs with SSH app can't be far away. People ARE writing apps for the Surface and the Windows 8 ecosystem.

Comparing this to my iPad which has about 95 apps where 30 of them are games. These are apps that I use every week and they are apps I'd tell my friend about. In this measure, as of today the Surface lacks behind. However, 90% of the big apps I care about are there like Amazon, Hulu, Netflix, Plex, MarkPad, Pulse, Podcasts, Skype, Flixster, FitBit, All Recipes, Remote Terminal and Remote Desktop, etc. Actually, the Google Search apps is fantastic, especially the Voice Search feature which is lots of fun to impress the family with.

The iOS ecosystem has a large number of really high quality apps. I have noticed with some digging there are some gems in the Windows Store like Discourse, NextGen Reader, Google Search, ReddHub, MetroTwit, and many others. They don't all have recognizable names yet, but with time I suspect we'll seem some unknowns independent publishers become knowns.

Integration

Watching "Justified" on my HDTV via AirPlay on an iPad talking to a RaspbmcWhat's integration mean? Well, things should just work together. I love AirPlay, for example. It just works great. You can be on your iPad, watching a movie and then just "throw" the video up to an AppleTV, or even a Raspberry Pi. If you live the Apple lifestyle, it pretty works all works together brilliantly. Our family has two iPads, an iPhone and two iPod touches. AirPlay works, iTunes servers are shared, happiness ensures. To get AirPlay to work with my PCs, I have to install AirServer (a brilliant app, by the way) so I can throw video or even mirror my iPad to my PCs.

The same applies to the Surface. I've got a "Homegroup" setup (took about 5 min) and when the Surface showed up, I added it to the Homegroup. This means that my HP printer just appeared as available and default on the Surface, which was impressive to me. Also, the other machines (my wife's, the kitchen PC, my home office machine) all shared files with the Surface, again without configuration as it's all part of the Homegroup.

Both the Surface and the iPad talked nicely to the Xbox using the SmartGlass app, as they should. If I've got a connected device I expect it to talk to other devices without complaint and in this case they did.

Where the Surface utterly fell down was when I introduced a micro-SD card. The iPad doesn't allow for extensible memory, but for the Surface RT it's a feature so I took a 64 gig mini SD card and put it in the near-hidden slot. I expected some kind of popup followed by an integration step where I'd click OK and then have more space to store my photos and movies.

It was not so, I'm afraid. The SD card showed up like just any other storage. OK, I'll add it to my Library Locations. Nope, you're prevented from adding Removable Storage to Libraries. I tried copying a bunch of Videos to the SD Card and they copied fine and played fine, but the videos (or music, or movies, or photos) don't show up in the Surface applications. Perhaps this can be fixed in some future update, but while I've taken my Surface from 32 gigs of storage to 96 gigs, it sure doesn't feel like it. I have to launch my videos from the Windows Explorer side and not get any integration on the tablet/full screen side of things. It's disappointing. Yes there are workarounds and hacks but there shouldn't have to be.

That said, having a USB port on the Surface is a plus. My USB mice and USB keys have all worked just fine.

As my friend Jon says: "Apple solves media sharing, Windows solves file sharing. It would be nice if one of them solved both. Completely."

Getting Work Done

Word is a decent Blogging PlatformWell, depends on what your work is. Take this blog post for example. It's just text and some pictures. You need a good blog editor, support to get the data into your blog and some picture editor. Being able to assemble a competent blog post (or doctoral thesis for that matter) is a good litmus test for any device that purports to do more than play games and watch movies.

I tried to write it on the iPad, which has a lot of great Markdown apps but no good XML-RPC blog front ends, and I don't run Wordpress. There is Blogsy, which is arguably the only decent blog editor on iOS, although there's also BlogPress. Blogsy is close and I may use it to fix the occasional typo from the road, but there's no way to crop, edit or resize photos. Fine, I'll use the iOS photo app or PhotoShop in iOS. There's not even a way to move an image like dragging it once its placed. This isn't the iPad hardware's fault but it does point out that it's challenging to do work when work consists of moving a lot of diverse data around without a file system.

The Surface RT fared a little better. Since the Surface  includes Word 2013 and Word supports the MetaWeblog interface out of the box I was able to type and edit this post in Microsoft Word (who knew that Word was a reasonable Blogging app?). It works pretty well as there are no great Blogging apps on the Windows Store as of this writing. Additionally, I wasn't able to find some kind of a free Paint.NET clone to crop and markup my screenshots. The closest I found was Artefacts but at $13.99 I wasn't willing to go for it. Fortunately the Free version of Artefacts supports cropping via its "reframe" command. It's a gorgeous app but I had to dig to find it.

I finished this post on my Ultrabook using my favorite (and the best) blogging app, Windows Live Writer. This makes me feel like I would personally be best served by an Ultrabook (or possibly a Surface Pro, which is effectively an Ultrabook) that would let me run any Windows application, whether it's in the Store or not. I want a small, touchable, fast machine that can do anything.

Conclusion

The iPad is a great tablet with a great ecosystem that is continuing to push the device to the limit. There are consistently great apps coming out for iOS. I'd love to see new features like picture in picture (PiP) or some basic multi-window multi-tasking. The hardware is solid and comforting. Pages and Numbers are great productivity apps for $10 additional each but the lack of seamless DropBox integration slows me down. ICloud syncing works great, however. I use my iPad for surfing, Netflix, Hulu, and Comics every day.

The Surface RT is a landscape tablet with an optional keyboard. It's got a great feel, good weight, is about the same size as an iPad but a little longer. The inclusion of Office (Word, Excel, etc) is a clever one and made my wife happy. I could see a Surface RT as a good balance between tablet and laptop for students, parents, and folks who can find apps that can do what what they need to do in the Windows Store.

An Ultrabook (I have a generic) is a 11" or 13" laptop with a touch screen. They almost all have fans - today - and they are fast, light and at least twice as much money as a tablet. They are full and fabulous "everything and the kitchen sink" machines. Some are good tablets like the Yoga, and some are great laptops. I suspect that at some future point I'll find a good touchscreen Ultrabook for around $1200 at a 13" size and it will become not only my primary machine but also my primary tablet. But in order for me to stop throwing my iPad or Surface in my backpack along with my laptop - as I do on every trip - Ultrabooks will need 10 hour battery lives, reliable touchscreens and lots of apps in the App Store.

It's a great time to be a user of consumer electronics. Whether it's the coming Surface Pro (I haven't seen one) or a possible MacBook Air with a touchscreen (I don't know of one) I believe there will be some great choices available this coming year.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

When in doubt, turn on Tracing

January 1, '13 Comments [12] Posted in ASP.NET | ASP.NET Web API
Sponsored By

One of my favorite posts that I've done is "The Internet is not a black box. Look inside."

I really want to encourage folks to look inside "black boxes" - or more accurately, what they perceive as black boxes - in order to solve their issues.

I got a great question from blog reader Eddie F. He also knows I don't like to waste keystrokes so he mentioned that I could blog the result if I answered his question. Hat tip to Eddie.

He says:

I have a case with an Entity Framework 5.0 entity that refuses to "PUT" to my ASP.NET WebApi controller (all .NET 4.5 RTM) if I add the [Required] data annotation to a property on my entity class which I find really bizarre.

So Eddie has an entity with the [Required] attribute on a property. When he PUTS (not POSTS) he gets an error:

var response = client.PutAsJsonAsync("/api/MagicPants/Update", entry).Result; 
//HERE IS THE POINT OF FAILURE when the [Required] attribute
// is added to the EF poco type PortfolioEntry.

If he removes [Required] it works. If he uses any other DataAnnotation like RangeValidation, it also works.

Eddie points out that he's Googled (with Bing) all over and found nothing. He has asked lots of friends and StackOverflow before asking me. Very thoughtful.

I replied with this to get more info.

What happens underneath? You're describing an interaction with a black box without pushing under....what does tracing say? What does Fiddler say?
http://blogs.msdn.com/b/henrikn/archive/2012/08/15/asp-net-web-api-released-and-a-preview-of-what-s-next.aspx

Eddie replied:

That question, along with your provided hyperlink to Henrik’s blog (bookmark… check) allowed me to discover web api tracing.  Genius!  I feel like I’ve been riding in the car, but now I feel like I’ve taken the wheel.  Thank you!

As an ASP.NET guy I take this to mean that Tracing isn't easily discoverable in the product. However, once you know it exists (through all of ASP.NET) things get interesting. You have to know to ask about Tracing (and hence, Google) before you can unlock its power. Most products have tracing or logging or "turn diagnostics up to 11."

Eddie said:

Tracing was very clear about the problem:

iisexpress.exe Error: 0 : Operation=FormatterParameterBinding.ExecuteBindingAsync, 
Exception=System.InvalidOperationException:
Property 'OrderOfMagnitude' on type 'TFSPortfolio.Models.PortfolioEntry' is invalid.
Value-typed properties marked as [Required] must also be marked with
[DataMember(IsRequired=true)] to be recognized as required.
Consider attributing the declaring type with [DataContract]
and the property with [DataMember(IsRequired=true)].

at System.Web.Http.Validation.Validators.ErrorModelValidator.Validate(ModelMetadata metadata, Object container)
...
at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)

I had the DataMember attribute on the property but not the IsRequired=True

So I add the attribute and bingo!

Even better, Eddie knows about T4 and is code-generating his Entities so he adds:

I’ll have to make another minor tweak to the T4 template for this attribute to fix this globally… gotta love T4 for this job.

A great result via a clarifying question about a question. When in doubt, turn on tracing!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

ASP.NET and Web Tools 2012.2 (Release Candidate)

December 13, '12 Comments [52] Posted in ASP.NET | ASP.NET Ajax | ASP.NET Dynamic Data | ASP.NET MVC | ASP.NET Web API
Sponsored By

All the parts of ASP.NET, all the subsystems are all part of the larger ASP.NET communityI've talked before in presentations that the ASP.NET and Web Tools team has been slowly externalizing pieces of ASP.NET. You've seen it in many pieces of the ASP.NET runtime moving into NuGet while also being open sourced, and you've seen it as we've moved big chunks of the "tooling" (that means the menus and dialogs you interact within Visual Studio when using ASP.NET) into external installers.

Why are we doing this? Because the Web moves faster than Visual Studio does. We want to be able to offer a stable ASP.NET core that you can count on while being able to offer new and powerful features more often as needed.

Visual Studio itself has moved to a faster update model and recently released Visual Studio 2012.1 (that's Visual Studio 2012 Update 1 if you prefer.) You can get the VS2012.1 update here or just wait for Visual Studio to popup some toast and let you know.

We're going to release an update to ASP.NET we'll call ASP.NET and Web Tools 2012.2. This will happen early next year but today you can download our Release Candidate! You can watch my presentation with Jon Galloway from the BUILD conference or read the release notes. This RC is, of course, newer than the one we released at BUILD and has a better name.

This is a tooling refresh of Visual Studio 2012 and extends the existing run time with new features without breaking existing applications. This adds new templates and features including:

  • Enhancements to Web Publishing unifying Web Application and Website project publish experience.  Selective publish, local/remote diffs and more.
  • Page Inspector has enhancements including JavaScript selection mapping and ability to see CSS updates in real-time.
  • New Web API functionality including support for OData, tracing and generating a help page for your API.
  • New MVC templates
    • You can create Facebook apps using the MVC Facebook template. In just a few easy steps you can create a Facebook Canvas Application that gets data from the logged in user as well and with friends.
    • The return and refresh of an all-new Single Page Application template allows developers to build interactive web apps using Knockout JavaScript library and a RESTful Web API.
  • Real-time communication via SignalR. This means SignalR, in case you haven't heard, is a real and official thing. It's fully supported by Microsoft.
  • Extensionless Web Forms via ASP.NET Friendly URLs which makes it easy for web forms developers to generate clean URLs without the .aspx extension. This can be used with existing ASP.NET 4.0 applications as well!
    • FriendlyURLs also makes it easier for developers to add mobile support to their applications, by supporting switching between desktop and mobile views.
  • Editor support for Knockout IntelliSense and pasting JSON as a class.

ASP.NET and Web Tools 2012.2 installs quickly and does NOT alter the current ASP.NET run time components or change the GAC. For a complete description see the Release Notes.

ASP.NET Fall 2012 Update for Visual Studio 2012 can be installed from the Fall 2012 Update home page(http://www.asp.net/vnext/overview/fall-2012-update). This is an update to Visual Studio 2012, which is required. This Release Candidate update does not support localized versions yet.  You see the new features in English but we'll will have localization support in upcoming RTM. It is an RC so there are some known issues. Be sure to check out the Release Notes for issues and workarounds.

Also be sure to get our "labs" component for Web Developers called Web Essentials. This is a place for Mads and the team to try out new features and play. When those features are baked, we'll graduate them to an update like this one!

Why isn't this called ASP.NET 4.6? Because it's not. The GAC'ed ASP.NET 4.5 doesn't change. This is mostly a tooling update as well as a collection of NuGet-based libraries that augment but don't replace ASP.NET 4.5. If we called if ASP.NET 4.6 then folks would think they needed to rush to update their servers. They don't. It's an update for "Web Tools for VS 2012" but that's lame, so since we got the VS guys to use the .1, .2, .3 scheme rather than September Update CTP Refresh, then we can make things easier by calling this Web Tools 2012.2.

This .2 release is just a step towards a more componentized "One ASP.NET." I hope you enjoy the direction we're heading. We've got some new things planned like a unified "File New ASP.NET Application" dialog, a better way to add your own templates and share them with the community, and a more level playing field for everyone.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Comparing two techniques in .NET Asynchronous Coordination Primitives

December 11, '12 Comments [13] Posted in Back to Basics | Learning .NET
Sponsored By

Last week in my post on updating my Windows Phone 7 application to Windows 8 I shared some code from Michael L. Perry using a concept whereby one protects access to a shared resource using a critical section in a way that works comfortably with the new await/async keywords. Protecting shared resources like files is a little more subtle now that asynchronous is so easy. We'll see this more and more as Windows 8 and Windows Phone 8 promote the idea that apps shouldn't block for anything.

After that post, my friend and mentor (he doesn't know he's my mentor but I just decided that he is just now) Stephen Toub, expert on all things asynchronous, sent me an email with some excellent thoughts and feedback on this technique. I include some of that email here with permission as it will help us all learn!

I hadn’t seen the Awaitable Critical Section helper you mention below before, but I just took a look at it, and while it’s functional, it’s not ideal.  For a client-side solution like this, it’s probably fine.  If this were a server-side solution, though, I’d be concerned about the overhead associated with this particular implementation.

I love Stephen Toubs's feedback in all things. Always firm but kind. Stephen Cleary makes a similar observation in the comments and also points out that immediately disabling the button works too. ;) It's also worth noting that Cleary's excellent AsyncEx library has lots of async-ready primitives and supports both Windows Phone 8 and 7.5.

The SemaphoreSlim class was updated on .NET 4.5 (and Windows Phone 8) to support async waits. You would have to build your own IDisposable Release, though. (In the situation you describe, I usually just disable the button at the beginning of the async handler and re-enable it at the end; but async synchronization would work too).

Ultimately what we're trying to do is create "Async Coordination Primitives" and Toub talked about this in February.

Here's in layman's terms what we're trying to do, why it's interesting and a definition of a Coordinate Primitive (stolen from MSDN):

Asynchronous programming is hard because there is no simple method to coordinate between multiple operations, deal with partial failure (one of many operations fail but others succeed) and also define execution behavior of asynchronous callbacks, so they don't violate some concurrency constraint. For example, they don't attempt to do something in parallel. [Coordination Primitives] enable and promote concurrency by providing ways to express what coordination should happen.

In this case, we're trying to handled locking when using async, which is just one kind of coordination primitive. From Stephen Toub's blog:

Here, we’ll look at building support for an async mutual exclusion mechanism that supports scoping via ‘using.’

I previously blogged about a similar solution (http://blogs.msdn.com/b/pfxteam/archive/2012/02/12/10266988.aspx), which would result in a helper class like this:

Here Toub uses the new lightweight SemaphoreSlim class and indulges our love of the "using" pattern to create something very lightweight.

public sealed class AsyncLock
{
private readonly SemaphoreSlim m_semaphore = new SemaphoreSlim(1, 1);
private readonly Task<IDisposable> m_releaser;

public AsyncLock()
{
m_releaser = Task.FromResult((IDisposable)new Releaser(this));
}

public Task<IDisposable> LockAsync()
{
var wait = m_semaphore.WaitAsync();
return wait.IsCompleted ?
m_releaser :
wait.ContinueWith((_, state) => (IDisposable)state,
m_releaser.Result, CancellationToken.None,
TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
}

private sealed class Releaser : IDisposable
{
private readonly AsyncLock m_toRelease;
internal Releaser(AsyncLock toRelease) { m_toRelease = toRelease; }
public void Dispose() { m_toRelease.m_semaphore.Release(); }
}
}

How lightweight and how is this different from the previous solution? Here's Stephen Toub, emphasis mine.

There are a few reasons I’m not enamored with the referenced AwaitableCriticalSection solution. 

First, it has unnecessary allocations; again, not a big deal for a client library, but potentially more impactful for a server-side solution.  An example of this is that often with locks, when you access them they’re uncontended, and in such cases you really want acquiring and releasing the lock to be as low-overhead as possible; in other words, accessing uncontended locks should involve a fast path.  With AsyncLock above, you can see that on the fast path where the task we get back from WaitAsync is already completed, we’re just returning a cached already-completed task, so there’s no allocation (for the uncontended path where there’s still count left in the semaphore, WaitAsync will use a similar trick and will not incur any allocations).

Lots here to parse. One of the interesting meta-points is that a simple client-side app with a user interacting (like my app) has VERY different behaviors than a high-throughput server-side application. Translation? I can get away with a lot more on the client side...but should I when I don't have to?

His solution requires fewer allocations and zero garbage collections.

Overall, it’s also just much more unnecessary overhead.  A basic microbenchmark shows that in the uncontended case, AsyncLock above is about 30x faster with 0 GCs (versus a bunch of GCs in the AwaitableCriticalSection example.  And in the contended case, it looks to be about 10-15x faster.

Here's the microbenchmark comparing the two...remembering of course there's, "lies, damned lies, and microbenchmarks," but this one is pretty useful. ;)

class Program
{
static void Main()
{
const int ITERS = 100000;
while (true)
{
Run("Uncontended AL ", () => TestAsyncLockAsync(ITERS, false));
Run("Uncontended ACS", () => TestAwaitableCriticalSectionAsync(ITERS, false));
Run("Contended AL ", () => TestAsyncLockAsync(ITERS, true));
Run("Contended ACS", () => TestAwaitableCriticalSectionAsync(ITERS, true));
Console.WriteLine();
}
}

static void Run(string name, Func<Task> test)
{
var sw = Stopwatch.StartNew();
test().Wait();
sw.Stop();
Console.WriteLine("{0}: {1}", name, sw.ElapsedMilliseconds);
}

static async Task TestAsyncLockAsync(int iters, bool contended)
{
var mutex = new AsyncLock();
if (contended)
{
var waits = new Task<IDisposable>[iters];
using (await mutex.LockAsync())
for (int i = 0; i < iters; i++)
waits[i] = mutex.LockAsync();
for (int i = 0; i < iters; i++)
using (await waits[i]) { }
}
else
{
for (int i = 0; i < iters; i++)
using (await mutex.LockAsync()) { }
}
}

static async Task TestAwaitableCriticalSectionAsync(int iters, bool contended)
{
var mutex = new AwaitableCriticalSection();
if (contended)
{
var waits = new Task<IDisposable>[iters];
using (await mutex.EnterAsync())
for (int i = 0; i < iters; i++)
waits[i] = mutex.EnterAsync();
for (int i = 0; i < iters; i++)
using (await waits[i]) { }
}
else
{
for (int i = 0; i < iters; i++)
using (await mutex.EnterAsync()) { }
}
}
}

Stephen Toub is using Semaphore Slim, the "lightest weight" option available, rather than RegisterWaitForSingleObject:

Second, and more importantly, the AwaitableCriticalSection is using a fairly heavy synchronization mechanism to provide the mutual exclusion.  The solution is using Task.Factory.FromAsync(IAsyncResult, …), which is just a wrapper around ThreadPool.RegisterWaitForSingleObject (see http://blogs.msdn.com/b/pfxteam/archive/2012/02/06/10264610.aspx).  Each call to this is asking the ThreadPool to have a thread block waiting on the supplied ManualResetEvent, and then to complete the returned Task when the event is set.  Thankfully, the ThreadPool doesn’t burn one thread per event, and rather groups multiple events together per thread, but still, you end up wasting some number of threads (IIRC, it’s 63 events per thread), so in a server-side environment, this could result in degraded behavior.

All in all, a education for me - and I hope you, Dear Reader - as well as a few important lessons.

  • Know what's happening underneath if you can.
  • Code Reviews are always a good thing.
  • Ask someone smarter.
  • Performance may not matter in one context but it can in another.
  • You can likely get away with this or that, until you totally can't. (Client vs. Server)

Thanks Stephen Toub and Stephen Cleary!

Related Reading

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Updating my Windows Phone App to Windows Phone 8

December 8, '12 Comments [18] Posted in WinPhone
Sponsored By

Lost Phone Screen on Windows Phone 8Earlier this year I wrote a small Windows Phone 7 application in a day called Lost Phone Screen. It creates lock screens for you with your name and contact number on them to aid in finding your phone the old fashioned way when you lose it. No need for a GPS, just tell folks you have a small reward and give them a number to call. You can download it free now as folks will not pay 99 cents for anything except Angry Birds. But I'm not bitter. ;) Anyway, it works great on Windows Phone 7 and Windows Phone 7.5 (Mango.)

Recently I got a Nokia Lumia 920 with Windows Phone 8 and since there's a number of new APIs and features I could exploit - not the least of which being the ability to programmatically set the phone's Lock Screen without the user needing to do anything - I figured it was time to update it.

I encourage you to review the post From Concept to Code in 6 hours: Shipping my first Windows Phone App as a reminder of what the app did and the issues I had writing the Windows Phone 7.x version.

Here's what I had to think about updating the app for Windows Phone 8. Big thanks to my friend Justin Angel at Nokia for brainstorming on Skype with me and helping with the async code and resolution issues. His blog post on What's New in Windows Phone 8 was very useful, especially his little MultiRes helper class.

Updating The App

First, to be clear, the existing Windows Phone 7 app works great on Windows Phone 8 without ANY changes. It runs and behaves exactly on Windows Phone 8 as it did on Windows Phone 7. I wanted to update it in order to "light up" some the new features on the new OS.

Upgrading the Project to Windows Phone 8

Upgrading was easy, I opened the old project and was prompted to upgrade. I double-clicked on the WMAppManifest.xml and made sure to reassert some of the basic settings like icon sizes and tiles for my app, as well as confirming the capabilities that my app would need like photo access, etc.

I was sure to check the Supported Resolutions as I knew I'd need those later.

Windows Phone 8 supports three resolutions

Keeping two Branches vs. One Super Project

I went back and forth on this. It's an upgraded OS but 99% of the code will be shared. However, enough stuff has changed that I decided to make a branch in source control rather than make a single build. Honestly, there's likely no wrong answer here and you use what you're comfortable with. I could have to CSProj files if I liked, or just made a different Build Configuration (like Debug8 and Debug7, etc) but I understand my source control pretty well so I ended up with a phone70 and a phone80 branch and I switch between them. It's more likely that I'll be updating the phone80 branch then "back porting" new feature so for now this work fine, but know I can always make a single build if I want.

Ultimately though, I know that I need to make a build for Windows Phone 7.x and one for Windows Phone 8 but I can submit them each to the Store under the same name and the Store will do the right thing. If you've got Windows Phone 8 with a new resolution you'll get the right version as you can see in the screenshot below. I've submitted two XAP files.

Two versions of the same app in the Store, one for each phone

New Screen Resolutions

I updated my app a few weeks ago but my first good bug came in from a gent with a HTC Windows Phone device running at 1280x720, rather than 1280x768. He said my lockscreens were cropped! With Windows Phone 8 there's three resolutions, in fact as Justin points out:

The resolutions are: WVGA (480x800 pixels), also used in Windows Phone 7; WXGA (768x1280 pixels), essentially an HD version of WVGA; and the wildcard 720P (720x1280 pixels) that uses a different aspect ratio to WVGA and WXGA. You should be aware of these different resolutions, make sure to use relative <Grid /> positioning in laying out screens, and potentially different media assets for different resolutions.

It's less important that there's three resolutions but rather more interesting that 720p is a different aspect ratio! Turns out I was making a number of assumptions in my code, not the least of which being the screen resolution. I was assuming 15:9 as the aspect ratio like 800x480 and 1280x768, but 16:9 is 1280x720!

My initial reaction was, crap, now I have to actually think.

Turns out that it's easier than that. On all of my app's pages but one I was able to remove XAML code and hard coded margins and row definitions. I was actually being too specific and not letting the system lay itself out optimally.

I removed all my hard-coded margins and changed my Grids to use a RowDefinition of "*" which means "the rest of the space" like this:

<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
...
</Grid>

The first RowDefinition fills to the size of its content and the second just takes up the rest. This made all my pages look great on every resolution screen, and it was easy to test because I could just change the Emulator dropdown to select the various  resolutions:

Different Emulator Resolutions in a Dropdown

However, with these new resolutions, I did change my originally single SplashScreenImage.jpg to include one each for the three resolutions named SplashScreenImage.Screen-720p.jpg, SplashScreenImage.Screen-WVGA.jpg and SplashScreenImage.Screen-WXGA.jpg. You'll find that at least half your time doing mobile apps (regardless of Apple, Windows or Android) is getting the PNGs and artwork files correct).

Three new SplashScreens

I had (chose) to hard code some screen sizes in one place in the app. (I could have queried  Application.Current.Host.Content.ScaleFactor. Application.Current.Host.Content.ActualHeight and Application.Current.Host.Content.ActualWidth to be correct.) I have a VERY specific custom Image Cropping control that needed special handling for the 720p case, likely due to my lack of skill with XAML. I am told that only the most edgy of edge cases need to do this and often this is in the creation of pixel-perfect lock screens so you probably won't sweat it at all.

New Lock Screen API

Finally my app can update the Lock Screen without manual user intervention. This was my #1 request and everyone assumed it was my fault that the feature didn't exist. It's been added in Windows Phone 8.

If you app wants to change the Lock Screen it has to ask once and get permission. It has to be the "current lock screen provider." If it is, it requests access and then sets the lock screen.

if (!LockScreenManager.IsProvidedByCurrentApplication)
{
LockScreenRequestResult result = await LockScreenManager.RequestAccessAsync();
if (result == LockScreenRequestResult.Granted)
{
SetAsWallpaper(filename);
}
}
else
{
SetAsWallpaper(filename);
}

SetAsWallpaper is just a helper around LockScreen.SetImageUri().

private void SetAsWallpaper(string filename)
{
string realPath = "ms-appdata:///local/" + filename;
Debug.WriteLine(realPath);
//Debug.WriteLine(ApplicationData.Current.LocalFolder.Path);

LockScreen.SetImageUri(new Uri(realPath, UriKind.Absolute));
}

And that's it. Lovely and simple. BUT.

A Very Important Reminder when using Asynchronous APIs

In Windows 8 and Windows Phone 8 (since the Windows 8 magic dust is under Windows Phone 8) everything is all about asynchrony and non-blocking APIs. Before I'd just save the wallpaper and you'd wait and you had no choice. Now all the underlying APIs are asynchronous  (non-blocking) and we as developers have await/async keywords to make things simple, right?

Sure, but my second lovely bug that showed up was when folks mashed on the Save button many times. Because everything is non-blocking this would fire off many save requests and eventually they'd collide at the file system with an "Access Denied" or something equally useful.

I have this shared resource that I need to protect access to but I don't want to block the UI. Michael L Perry has a great solution for this that should probably be built into the Windows Phone SDK (unless it is and we've all missed it?) in his Awaitable Critical Section helper. This helper lets us use the familiar using{} block structure in situations where we are using async and await inside what would have been a lock(){} block.

As Michael points out, you CAN'T do this because you can't await in a lock.

lock (this)
{
FileHandle file = await FileHandle.OpenAsync();
await file.WriteAsync(value);
file.Close();
}

But with his helper you can do this:

using (var section = await _criticalSection.EnterAsync())
{
FileHandle file = await FileHandle.OpenAsync();
await file.WriteAsync(value);
file.Close();
}

And I did just that.

Analyze

When you're done, make sure you run the Windows Phone Application Analysis tools see how your application does. Does it use too much memory? Use up the battery? Does it startup in less than a second?

Windows Phone Application Analysis

This is fascinating stuff. Don't work so hard on your app and forget to profile it.

New Things to Remember when Submitting Your App and Submitting Two Versions

I fixed some bugs in the Windows Phone 7 version, changed that XAP's version number and submitted it as a small upgrade. Folks who have Windows Phone 7.x will get prompted to update their app. This version, as you'll recall, doesn't auto-update the lock screen because it can't.

I go into the Phone Marketplace and click Update App from the Dashboard. There's the Marketplace before my update, showing the 7.1 app:

Windows Phone 7 app

I click Update selected and upload the new Windows Phone 7.1 targeted XAP that I just built. After that's uploaded I change the dropdown and upload the Windows Phone 8 XAP. I make sure in both cases to upload a Release XAP and the "AnyCPU" version.

Windows Phone 8 app

I am keeping the Windows Phone 8 one a few versions ahead for my own sanity. It makes sense to me and it helps me remember what's "newest" even though it only matters that the new versions be higher than the previous versions.

Be sure to check all your text, your descriptions and icons to make sure they are correct.

Time Spend Coding vs. Time Spend Editing PNGs

Goodness, I swear I have spent more time messing with screenshots and PNGs than coding.

Here's the thing: Mobile app development is all about the Screenshots and Icons.

There's so many resolutions and assets and different scenarios where your application can be showcased that it's worth spending some time getting really good at PhotoShop or Paint.NET. I'm doing all my work in Paint.NET, in fact.

Because there's three resolutions you'll want to make note that you need three sets of screenshots! Fortunately there's a screenshot cool built into the Emulator and Windows Phone also supports in-device screenshots (finally) by pressing Power+Windows Key.

It may not be obvious from this picture of the marketplace submission but you need to click WXGA and 720p and upload separate screenshots for each one! Otherwise your potential users won't see your app looking exactly as it will on their device. Tedious, but crucial.

Three sets of screenshots for three resolutions

Truly, this became an asset management chore. I ended up with a folder fill of JPGs and PNGs and only kept my sanity with some reasonable file name conventions.

naming screenshots and splashscreens reasonably.

You will end up with at least 24 screenshots (3x8) plus three splash screens, several icon sizes and you'll also want to test on both the Dark and Light themes.

Conclusion

In the end, it will be seamless for your end users. Folks who have Windows Phone 8 will get their updates from your WP8-XAP and Windows Phone 7.x folks will get theirs from your WP7-built XAP. This whole thing took about 3 hours and most of that time was spent doing screenshots.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.