首页 新闻 会员 周边

.Net平台独立存储的问题,看代码

0
[已解决问题] 解决于 2015-06-18 11:02

问题出在最后一行,在执行Remove方法时,会提示目录正在被使用的异常,但我看不出哪里在使用。

using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly())
            {
                store.CreateFile("TestFileA.txt");
                store.CreateFile("TestFileB.txt");
                store.CreateFile("TestFileC.txt");
                store.CreateFile("TestFileD.txt");
            }
            IEnumerator allFiles = IsolatedStorageFile.GetEnumerator(IsolatedStorageScope.User);
            long totalSize = 0;
            while (allFiles.MoveNext())
            {
                IsolatedStorageFile storeFile = (IsolatedStorageFile)allFiles.Current;
                totalSize += (long)storeFile.UsedSize;
            }
            Console.WriteLine("总大小:{0}", totalSize);
            Console.WriteLine("按任意键结束..");
            IsolatedStorageFile store2 = IsolatedStorageFile.GetUserStoreForAssembly();
            store2.Remove();

北在北方的主页 北在北方 | 初学一级 | 园豆:180
提问于:2015-06-16 20:01
< >
分享
最佳答案
0

using(var stream = store.CreateFile("TestFileA.txt"))

{
}

 

奖励园豆:5
Launcher | 高人七级 |园豆:45045 | 2015-06-17 17:26

明白了,我知道是怎么回事了,我把using错以为会将代码段里的所有资源释放。

北在北方 | 园豆:180 (初学一级) | 2015-06-18 11:02
其他回答(1)
0

估计是有文件在用吧,https://msdn.microsoft.com/en-us/library/7ay840d1(v=vs.110).aspx官方的说明 If any of the directories or files in the store are in use, the removal attempt for the store fails and the store is marked for removal. Any subsequent attempts to modify the store throw an IsolatedStorageException.

使用sysinternal工具包中的procmon可以看看到底都是谁在使用这个目录

2012 | 园豆:21230 (高人七级) | 2015-06-17 14:09

还是没搞明白。直接运行移除的代码能够陈宫,但是先执行创建文件,然后马上执行移除代码就会报错,创建文件时用的using也应该把创建时占用的资源释放了,为什么还是不行能?!

支持(0) 反对(0) 北在北方 | 园豆:180 (初学一级) | 2015-06-17 14:44

虽然没有解决问题,但你提到的工具很新鲜。

支持(0) 反对(0) 北在北方 | 园豆:180 (初学一级) | 2015-06-18 11:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册