#async task and the for loop bug

I have used various flavours of async task implementation.
* WP7 / async CTP / v3 VS 2010
* Win8 / VS 2012
* Azure / VS 2012
* SL / async targetting pack / VS 2012

I blogged about how i had issues with #async on #aszure and funnily enough i wasn’t the only one. As discussed in https://invokeit.wordpress.com/2012/11/07/windows-azure-and-async-task-mechanism-async/ if you use something like this

AsyncDataSourceObj aeo = new AsyncDataSourceObj();

protected async Task BuildFilmDataSet()
    Films films = await aeo.GetFilmData();
    foreach(var film in films)
        Cinemas cinemas = await aeo.GetCinemaData(film);

        // do things

        // do more things 

It doesn’t work and a little investigation showed me that i wasn’t doing anything wrong.

The moment await aeo.GetCinemaData(film); gets called, the execution instead of awaiting moves to the next iteration of for loop. Why in the world you would want that ? I am sure if you wanted that one would have used Parallel.For instead.

For some reason, the creators thought that we clever people wouldn’t ever want to do a async call in for loop. I mean its not like its the most common loop usage etc…

The suggestion is to use Task.Yield() (or TaskEx.Yield) within for loop

It however doesn’t always work. I have tried it with my last Silverlight + Async Targetting pack and its still the same. Infact I had to revert to event based async in that case.

Here’s a screen of azure sample in action

High Performance Touch Interface #wpdev #wp7dev

Every now and again i come across developer questions like why is manipulation delta slow etc. Let me tell you why.

UIElement Silverlight for #windowsphone exposes a few events like


Public eventSupported by Silverlight for Windows Phone ManipulationCompleted Occurs when a manipulation and inertia on the UIElement is complete.
Public eventSupported by Silverlight for Windows Phone ManipulationDelta Occurs when the input device changes position during a manipulation.
Public eventSupported by Silverlight for Windows Phone ManipulationStarted Occurs when an input device begins a manipulation on the UIElement.

These are high level touch interfaces and there is a significant overhead in reporting (and hence delay etc).

If you are say drawing on a bitmap or canvas, you dont want a min delta change before event is fired. For that lets look at low-level interface exposed in Silverlight.


Public eventStatic memberSupported by Silverlight for Windows Phone FrameReported Occurs when the input system promotes a Windows 7 touch message for Silverlight.

Touh.FrameReported is a low level method and has little overhead and is very very precise. Let me give you a code sample

Touch.FrameReported += Touch_FrameReported;

you can do above in Loaded event. Here’s the implementation of the Touch_FrameReported handler. WorkArea is Canvas in this. I have also used this in conjugation with WritableBitmap

private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        // Determine if finger / mouse is down
        point = e.GetPrimaryTouchPoint(this.workArea);
        if (point.Position.X < 0 || point.Position.Y < 0)
        if (point.Position.X > this.workArea.Width || point.Position.Y > this.workArea.Height)
        if (this.lbLetter.SelectedIndex == -1)
        switch (point.Action)
            case TouchAction.Down:
                draw = true;
                old_point = point;
                goto default;
            case TouchAction.Up:
                draw = false;
        MessageBox.Show("Application encountered error processing last request.");

I hope this is useful to #windowsphone developers out there.

Go a2b progress #wp7 #windowsphone #wp7dev

Every couple of weeks i usually come back to Go a2b. I recently realised that it wasn’t tethering that was causing me to exceed my mobile data limits. It was the fact that they had not put me on the right package 🙂 So while commuting in the traing, i have started testing Go a2b again.

I got the course based map turning correctly. I was so happy that i submitted it for beta. Then last night i had an epiphany and i got the zoom issue sorted. Now you can zoom in and out without any issues. no image corruption / lag any more. However i screwed up the map rotation 😦 i guess i have to check it again and go for a drive later on.

I love windowsphone. Its almost been a year and this i guess is the biggest app. Currently support maps are Bing, OpenStreet, Osmarender and Google maps. I tried yahoo but i had issues, I am looking into Nokia maps.

Windows Phone Dev in 2011

I think i got my HTC Mozart 7 some time in March 2011. After using it for a week or two, i registered myself as a Developer and started writing my first app Scribble in April. I think I spend 2 weeks writing it.

This was the first time i was coding Silverlight and its been fun.

Scribble: Initial effort – 2 weeks. It was my first try at Silverlight app and it was a simple drawing app – having used the word simple, it did a lot of things – use photochooser task, save to Photo Library etc. It even supported multi-touch – It was a great learning experience.

Alarm Clock: I spent a good 2 / 3 weeks writing this and yes i love this app – I use it as my Alarm clock – especially since Mango update as i can now have alarm without app running 🙂 –

LearnToWrite: 1 week – this was the simplest app i have written. Just features simple alphabets and numbers.

Sliding Keyboard: I wrote the above 3 apps trying not to write Sliding Keyboard. I just couldn’t get it out of my head and no matter how hard i thought, i wouldn’t figure out how i would achieve it. However I got it running in 2 weeks. And it went live in June 2011. Publishing v1.0 was a big mistake – it got slated on so many levels. Over the next couple of months, i cursed myself enough number of times. I have spend weeks and weeks since initial release – now it stands at version 3.2. It has taught me the most – it taught me humility – i am good at what i do and i realised that customer doesn’t care about how hard you are trying – they just want the product to work. I also learned that no one reads the description 🙂

The total downloads stand at 22,822 – Paid downloads are just over 1216. Here’s the download chart

I think it has been a very trying year – as a WP7 user I love the phone.

As a developer – I have mixed feelings – I love and hate the fact that API is restrictive. Microsoft have been fantastic in testing the apps – Everything has been as smooth – they test the apps better than i ever do. Thank you.

As of 2012, I am writing a couple of apps. Let’s see what this year holds.

What happened to Slydr 2.6 ?

I submitted Slydr 2.6 Friday the 6th Jan as i though i’d better update NoDo users with latest changes. I branched current Mango code base and made changes to revert the code to NoDo compatible code. I didn’t realise it but i left Mango version of Silverlight Toolkit and 2.6 didn’t pass certification as the app crashes when you navigate to Settings page. This is what consumes the Silverlight toolkit based controls.

So what did i do ? Well to start with I pushed 3.2 (which is update to 3.1 Mango version and contains some bug fixes) and its currently in testing. I have also downloaded NoDo sdk to get my hands on NoDo Emulator so i can thoroughly test 2.6 when i push it for certificaiton in coming week.

Apart from that Cool Cam is close to completion. I have the photo viewer working correctly and all i need to do is get effects application code working correctly. I plan to finish it tonight and then hopefully i will polish it a bit (for example displaying a count down when using timer mode). Then comes the annoying part of localisation. I am keeping the text very simple and so i hope localisation is easy / more accurate.

Last week i also published entire word lists i have generated. I have uploaded 50k zip, entire zip and log file which details file count / word count etc etc.