Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static readonly AwaitableCriticalSection _criticalSection = new AwaitableCriticalSection();
- public static async Task<T> ReadJsonExCs<T>(String fileName)
- {
- if (String.IsNullOrEmpty(fileName))
- return default(T);
- return await await Task.Factory.StartNew(async () =>
- {
- using (var section = await _criticalSection.EnterAsync())
- using (var store = IsolatedStorageFile.GetUserStoreForApplication())
- using (var stream = new IsolatedStorageFileStream(fileName, FileMode.Open, store))
- using (var sr = new StreamReader(stream))
- using (var jr = new JsonTextReader(sr))
- return await jr.ReadJsonAsyncTask<T>();
- });
- }
- public static async Task<bool> WriteJsonExCs<T>(String fileName, T content)
- {
- if (String.IsNullOrEmpty(fileName))
- return false;
- return await await Task.Factory.StartNew(async () =>
- {
- using (var section = await _criticalSection.EnterAsync())
- using (var store = IsolatedStorageFile.GetUserStoreForApplication())
- {
- store.CreateFolderIfNecessary(fileName);
- using (var stream = new IsolatedStorageFileStream(fileName, FileMode.Create, store))
- using (var sw = new StreamWriter(stream))
- using (var jw = new JsonTextWriter(sw))
- await jw.WriteJsonAsyncTask(content);
- }
- return true;
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment