C# BlackBerry Push Service SDK – Part V

Asynchrony

To be honest porting an API from one language to another can be pretty dull however once the grunt work is finished you can sometimes tweak the code to take advantage of specific language and/or platform features.

Since the shape of the existing API is synchronous I knew early on that changing the communications stack from blocking to non-blocking would be high on the ToDo list – to be fair if .NET did not have the async/await keywords I wouldn’t have bothered as writing async code without this feature is difficult and error-prone.

With this in mind I started with the lowest layer code that handled the request/reply over HTTP with the PPG inside IPapService – fairly simple since the comms classes already have Task-based wrappers.

After that follow the logic (and the build errors) into IPushService. The public API featured simple changes however under the covers the changes were more widespread…

ISubscriptionService is teeming with multi-threaded parallelised code so not only were there API changes but there was also an opportunity for refactoring a lot of the job partitioning logic into something much more concise and therefore easier to understand.

All this work meant that it was easy to update the acknowledgement HTTP handlers so that they are now implementing IHttpAsyncHandler which is good news!

So where are we? Well the CodePlex project has been created and the source will be checked in over the next few days – initially for Visual Studio 2010 but with VS2012 .NET 4.5RC version to follow.

C# BlackBerry Push Service – Asynchrony

Once I completed and tested this code I will be looking at which API segments can be switched into Task based async methods.

The communication methods that form the IPapService and IPushService, the synchronisation and PPG notification methods in ISubscriptionService are all obvious candidates as they currently rely on blocking I/O calls.

I will be releasing three solutions;

  • VS2010 + Async CTP
  • VS2012 + .NET 4
  • VS2012 + .NET 4.5

Please don’t thank me all at once… Rest assured I have my reasons for doing this!