IntroductionThere's a requirement that Windows Phone 7 applications not use more than 90 MB of memory to run. One might wonder how to know how much memory that their program is consuming. You can find that information through the DeviceExtendedProperties class. Given the myrid of programs on Windows Mobile and Android devices that display the technical details of a device I know it is tempting to surface some of this information up to a user. But Microsofts guidance on using it is that the information shouldn't be surfaced. Nor should you try to parse or process this information on the device. Rather the information exposed through this API should be for diagnostic purposes. Note that using this API in your programs will cause the program to need the DeviceInformation permission. The DeviceExtendedProperties class has two methods that are of interest. object GetString(string) and bool TryGetString(String, out object). For both methods the string argument is the name of the property to be retrieved. The first method will return the value of a property of throw an exception of that property cannot be read. The second method will return true and copy the value of a property to the out variable if the property can be read, otherwise it returns false. Some of the properties may not have values or may be blank. Here are some of the properties that can be retrieved To demonstrate the use of this class there's a link to download sample code at the top of this article. The code retrieves the values for a few of these properties and displays them. C# Code public void UpdateProperties()
{object temp = null;
;
DeviceManufacturer = (DeviceExtendedProperties.TryGetValue("DeviceManufacturer", out temp))
? (temp as string)
: String.Empty;
DeviceName = (DeviceExtendedProperties.TryGetValue("DeviceName", out temp)
? (temp as string) : string.Empty);
DeviceUniqueID = (DeviceExtendedProperties.TryGetValue("DeviceUniqueID", out temp)
? (temp as byte[])
: new byte[0]);
DeviceFirmwareVersion = (DeviceExtendedProperties.TryGetValue("DeviceFirmwareVersion", out temp)
? (temp as string)
: String.Empty);
DeviceHardwareVersion = (DeviceExtendedProperties.TryGetValue("DeviceHardwareVersion", out temp)
? (temp as string)
: String.Empty);
DeviceTotalMemory = (long)DeviceExtendedProperties.GetValue("DeviceTotalMemory");
ApplicationCurrentMemoryUsage = (long) DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage");
ApplicationPeakMemoryUsage = (long) DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage");
}Output Download Sample Project Download source files -130 kb |