If you have multithreading in Windows Phone 7 do you need multitasking?

Exploring how WP7 handles multiple application threads

Microsoft’s decision to block multitasking for Windows Phone 7, at least in the initial release, unleashed complaints from some developers and pundits. It was a step backward! The Apple-fication of Windows Mobile and so on.  Not everyone agrees. One who doesn't is Windows developer, author and blogger Kevin Hoffman. Low-level access is rarely needed, he says, especially if Microsoft follows through on its promises for a rich set of APIs, and the companion notification service, which will give Windows Phone developers access to a full set of device features and services. (He's got experience building iPhone applications, too, and he compares the two operating systems in a "Network World" interview.)Hoffman says Microsoft's approach will render multitasking unnecessary for all but a handful of applications. Software engineer Doug Boling, who specializes in Windows Embedded CE and Windows Mobile development, has been exploring what programmers can do with the multithreading capabilities of WP7, something I've not seen addressed before. He has a detailed blogpost of this experience, based on working with WP7 emulator image contained in the April 2010 WP7 software build. (In March, another developer  found an emulator bug, apparently confirmed, that can mess up multithreading in some cases. I'm don't know if Microsoft has addressed that since then.)“This isn’t the place for a treatise on multithreaded managed applications,” he writes. “But briefly, very briefly, Windows Phone applications can be multithreaded.  The main thread of the application calls the appropriate methods to create the main application form and is the “user interface thread”.  Other threads created by the application can’t directly interact with the user interface.  These threads are called “worker threads” or “background threads”.”Boling notes that when an application is sent to the background, the foreground thread is suspended but any worker threads running at the time keep running.  “These worker threads can call base class library methods such as querying the file system, reading and writing files, and such even while the application is ‘suspended,’” he writes.These worker threads can invoke a method on the suspended foreground thread. WP7 queues these invocations and holds them until the application resume. Then the queued calls are invoked in order.“So, while true multitasking doesn’t exist on the Windows Phone, applications can ‘borrow’ some background processing time as long as the system is lightly loaded,” he writes.When a worker thread tries to invoke a method on the foreground thread, that request is queued but not executed.  When the application is resumed, the queued calls are invoked.John Cox covers wireless networking and mobile computing for “Network World.”

Twitter: http://twitter.com/johnwcoxnww

Email: john_cox@nww.com

Blog RSS feed: http://www.networkworld.com/community/blog/2989/feed

Join the Network World communities on Facebook and LinkedIn to comment on topics that are top of mind.
Now read: Getting grounded in IoT