在前不久微软在英国的Tech Day上,微软的PPT中透露应用程序可访问的存储空间只有2G(参见http://www.wpmind.com/news/2010/04/20/windows-phone-7-uk-tech-day.html)。而不是以前大家估计的所有手机存储空间容量。
为了验证这一说法,特编写程序验证了一下。
程序中主要用到的代码如下:
1. 进度条定制:在Silverlight 开发中,所有控件都用XAML来定制,并且可以很方便的加上各种渲染效果。以前我们想要一个垂直的进度条的话,相对是比较复杂的。现在,很简单,只需要在进度条的XAML中加上旋转角度的渲染器,则该控件就会旋转一定的角度:
<ProgressBar Height="40" HorizontalAlignment="Left" Margin="32,532,0,0" Name="progressBar1" VerticalAlignment="Top" Width="460" IsIndeterminate="False" Foreground="Green" Minimum="0" Maximum="100" Value="0"> <ProgressBar.RenderTransform> <RotateTransform Angle="-90"></RotateTransform> </ProgressBar.RenderTransform> </ProgressBar> |
2. 独立存储:所有程序运行在自己的独立存储空间中,不能跨界访问其他地方的文件。使用独立存储的Demo 如下:
IsolatedStorageFile storeFile = IsolatedStorageFile.GetUserStoreForApplication(); //获取独立存储对象 this.textBlockPageTitle.Text=storeFile.Quota.ToString(); //获取独立存储的空间配额 this.textBlockListTitle.Text = storeFile.AvailableFreeSpace.ToString(); //获取独立存储的可用空间大小 string fileName = System.IO.Path.Combine("data", i.ToString() + ".txt"); //构造相对存储文件路径 using (IsolatedStorageFileStream f = storeFile.OpenFile(fileName, System.IO.FileMode.Create)) //使用IsolatedStorageFileStream来读写文件 { byte[] content = new byte[1024 * 1024]; f.Write(content, 0, content.Length); f.Flush(); f.Close(); } |
经过测试,程序运行的时候,你会发现程序的空间配额远远大于可用空间。可能这里空间配额获取了整个手机(模拟器)的可用空间,但是可用空间只是2G大小。当程序持续运行写入数据的时候,写够2G的数据还要继续写的话,程序就会得到IO异常。