私はデータベースを最初に作成し、そこにデータを保存するアプリケーションを作成しました。 ユーザーがリセットボタンをクリックしたときにこのデータベースとそのファイルを削除しますが、「これは別のプロセスで使用されています」というエラーが表示されます。私はそれを削除し、リセットボタンをクリックすると、データベースを再作成したい。何か案は?wp7でのアプリケーション設定のリセット
答えて
この原因の最も一般的な原因は、スレッドにあります。安全でない Windows Phoneで隔離されたストレージとのやり取りの性質。データベースをどのように実装していても(ファイルや一連のファイルの中にあっても)、あるレベルで独立したストレージとやりとりしています。
私は非常にお読みになり、遠くに行く前にthis overview of isolated storageを理解していることを強くお勧めします。
あなただ発言:
これは
は私はあなたのデータベースのものを行うために、サードパーティのライブラリを使用していると思わせる別のプロセスで使用されています。この例外/エラーは、ライブラリ自体が独立したストレージにアクセスできない場合にスローされます。どのようにデータベースを実装しているかを正確に知らなければ、あなたの状況に正確に話すのは難しいです。
IsolatedStorageを再作成することはありません。Isolated Storageは、アプリケーションがアクセスできるディスクスペースのコレクションを定義するために使用される用語です。フォルダのように、このディスクスペースにはルートがあり、作成するファイルのみが含まれています。
分離ストレージにアクセスするとき、あなたがそうのようにC#でusingキーワードを使用することを確認し、スレッドの例外を避けるために:スレッドの安全性の問題に役立つはず
namespace IsolatedStorageExample
{
public class ISOAccess
{
// This example method will read a file inside your Isolated Storage.
public static String ReadFile(string filename)
{
string fileContents = "";
// Ideally, you should enclose this entire next section in a try/catch block since
// if there is anything wrong with below, it will crash your app.
//
// This line returns the "handle" to your Isolated Storage. The phone considers the
// entire isolated storage folder as a single "file", which is why it can be a
// little bit of a confusing name.
using(IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAppliaction())
{
// If the file does not exist, return an empty string
if(file.Exists(filename))
{
// Obtain a stream to the file
using(IsolatedStorageFileStream stream = File.OpenFile(filename, FileMode.Open)
{
// Open a stream reader to actually read the file.
using(StreamReader reader = new StreamReader(stream))
{
fileContents = reader.ReadToEnd();
}
}
}
}
return fileContents;
}
}
}
を。私は非常にお勧めしますもう一つは、使用してIsolatedStorageにアクセスするクラスを実装している
// BE VERY CAREFUL, running this method will delete *all* the files in isolated storage... ALL OF THEM
public static void ClearAllIsolatedStorage()
{
// get the handle to isolated storage
using(IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
{
// Get a list of all the folders in the root directory
Queue<String> rootFolders = new Queue<String>(file.GetDirectoryNames());
// For each folder...
while(0 != rootFolders.Count)
{
string folderName = rootFolders.Dequeue();
// First, recursively delete all the files and folders inside the given folder.
// This is required, because you cannot delete a non-empty directory
DeleteFilesInFolderRecursively(file, folderName);
// Now that all of it's contents have been deleted, you can delete the directory
// itsself.
file.DeleteDirectory(rootFolders.Dequeue());
}
// And now we delete all the files in the root directory
Queue<String> rootFiles = new Queue<String>(file.GetFileNames());
while(0 != rootFiles.Count)
file.DeleteFile(rootFiles.Dequeue());
}
}
private static void DeleteFilesInFolderRecursively(IsolatedStorageFile iso, string directory)
{
// get the folders that are inside this folder
Queue<string> enclosedDirectories = new Queue<string>(iso.GetDirectoryNames(directory));
// loop through all the folders inside this folder, and recurse on all of them
while(0 != enclosedDirectories.Count)
{
string nextFolderPath = Path.Combine(directory, enclosedDirectories.Dequeue());
DeleteFilesInFolderRecursively(nextFolderPath);
}
// This string will allow you to see all the files in this folder.
string fileSearch = Path.Combine(directory, "*");
// Getting the files in this folder
Queue<string> filesInDirectory = iso.GetFileNames(fileSearch);
// Finally, deleting all the files in this folder
while(0 != filesInDirectory.Count)
{
iso.DeleteFile(filesInDirectory.Dequeue());
}
}
:あなたが何をしたいかに向けて、より具体的に参考にするには、以下の方法(あなたが上記のクラスにこれを追加することができます)を見てみましょう記載されている "マルチスレッドシングルトンパターン" here.
希望です。コードは「現状のまま」提供されていますが、私はそれをコンパイルしていませんが、一般的な概念はすべてそこにありますので、何か問題があれば、MSDNドキュメントを読んで私がどこにいるのか見てください。しかし、私はあなたに保証します、これはほとんどが私の機能コードからコピーされているので、ほんの少しのファンガガリングで適切に動作するはずです。
- 1. OSのアプリケーション設定のWP7アプリケーション設定ページ?
- 2. 設定のボタンからiOSアプリケーションの設定をリセットする
- 3. WP7アプリケーションを設計する
- 4. エンタープライズアーキテクトのリセット設定
- 5. WP7 - 既定のアプリケーションでファイルを開く?
- 6. WP7アプリケーションに設定値を保存する最善の方法
- 7. wp7アプリケーションでタイマーを設定するには?
- 8. WP7のSilverlightアプリケーションで
- 9. 特定のイベントでアプリケーションをリセットする
- 10. 同期VS設定のリセット
- 11. Androidアプリケーションのロケール設定後にSharedPrefsがリセットされる
- 12. ユーザースコープのアプリケーション設定は常にデフォルトにリセットされます
- 13. iosアプリケーションの通知設定をリセットする方法
- 14. ビジュアルスタジオ2017リセット設定
- 15. wp7/wp7.1のユーザー設定を検出
- 16. WP7での常設のバックグラウンドタスク
- 17. WP7:アプリケーションのバックグラウンド(マンゴー)
- 18. iOS - アプリケーション設定、スイッチをリセットしようとしています
- 19. iPhoneアプリケーションのリセット
- 20. Androidの復元と設定のリセット
- 21. React.jsの状態の設定とリセット
- 22. 設定をリセットする
- 23. FacebookアプリケーションとWP7
- 24. WP7アプリケーションをローカライズ
- 25. WP7 Appのページ間で文字列の値を設定する
- 26. アプリケーション実行中のwp7バックグラウンドプロセス
- 27. WP7地図アプリケーションの起動
- 28. WP7の多言語アプリケーション
- 29. WP7アプリケーションの展開用プレゼンテーション
- 30. wp7にListPickerを設定する
どのようにファイルを削除しますか?ファイル名を指すすべてのDbContextインスタンスを閉じて処分しましたか? –
あなたはどのくらいのデータを取得していますか?多分ApplicationSettingsは十分です。 –
IsolatedStorageデータベースを再作成し、イメージファイルとオーディオファイルを削除する –