为什么在 Windows Phone 7 上退出时独立存储不会删除最后两个临时文件?
我编写了一个使用独立存储存储数据的应用程序,我希望在数据变旧时定期清除这些数据。我编写了一个从 Closing 调用的函数,该函数检查隔离存储中是否有旧数据并将其删除。
该例程将删除目录中除最后两个文件之外的所有文件。当我调试代码时,我可以看到它对这些文件执行 DeleteFile 方法。我什至在调用 DeleteFile 之后立即检查该文件是否仍然存在。根据调试器的说法,它没有。
然而,当应用程序再次启动时,最后文件的旧数据仍然位于独立存储中。考虑到这可能是一个竞争条件,我在删除路由之后放置了 Thread.sleep(1000) 。
手机不考虑此延迟,并在执行 delte 代码后立即退出。我找不到与 DeleteFile 相关的刷新命令,因为当时我没有对流的引用。
还有其他人发现过这个或类似的东西吗?我是否缺少魔术刷新方法,或者这是手机isolatedStorage实现中的缺陷?
I have written an application that uses Isolated storage store data that I want to clear out on a periodic basis when it gets old. I have written a function that is called from Closing that checks the isolated storage for old data and deletes it.
This routine will delete everyfile that it is supose too except the last two files in the directory. When I debug the code I can see it execute the DeleteFile method on those files. I even when as far as checking right after the call to DeleteFile to see if the file still exists. According to the debugger it does not.
Yet when the appication starts up again the old data is for those last files is still in isolated storage. Thinking that it may be a race condition I put a Thread.sleep(1000) after the delete routeines.
The phone does not honor this delay and exits immediately after executing the delte code. I could not find a flush command that would be related to DeleteFile as I don't have a reference to a stream at that point.
Has anyone else found this or something similar? Is there a magic flush method I am missing or is this a defect in the phone IsolatedStorage implementation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我同意马特和马蒂厄的观点。
但也想问你是否尝试过截断文件?
<代码>
isolatedStorageFileStream isfStream = newisolatedStorageFileStream(strXMLFile, FileMode.Truncate, isf);
i agree with Matt and Matthieu.
though also wish to ask u have u tried truncating the file?
IsolatedStorageFileStream isfStream = new IsolatedStorageFileStream(strXMLFile, FileMode.Truncate, isf);