Catching up this morning as you can see. :) Here’s a good blog post about how Windows Phone handles multitasking. Contrary to the naysayers, it’s pretty sophisticated and entirely in keeping with Microsoft’s goal to hit the high points with this first release.
The new Windows Phone programming model uses a custom built Silverlight runtime to execute 3rd party applications … you write Silverlight apps that can’t access the system and, according to Microsoft, can’t even run in the background. Fortunately, applications aren’t quite that limited.
If an application is running and the user hits the Windows or Search buttons, the application is not (normally) terminated. Instead the OS places the app in a “suspended” state in memory. If the user later returns to the application either by restarting it or simply hitting the back button to dismiss the newer screens, the application resumes.
When an application is sent to the background, the foreground thread is suspended. However, any worker threads currently running in the suspended application continue to run. 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”.
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.
Of course, “suspended” applications live on borrowed time. If the system needs the memory used by the application it will be terminated.
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. This sounds great and can be used to the advantage of the application. However, developers should understand this “feature” and if their applications have worker threads that don’t need to run while the application is suspended, they need to ensure that those “worker” threads block while the application is suspended.
Thanks to Robert Teague for the tip.
No comments:
Post a Comment