Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit fe97452

Browse files
abodalevskysergey-akhalkov
authored andcommitted
[WPF] Fix application crash when storage file was deleted while app is being active. (#897)
* Create file if non exist on each call * Added asyn operation
1 parent ef5ab89 commit fe97452

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

Examples/CodePushDemoApp/windows/CodePushDemoApp/CodePushDemoApp.nuget.targets

Lines changed: 0 additions & 9 deletions
This file was deleted.

windows/CodePush.Net46/Adapters/Storage/ApplicationDataContainer.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ public class ApplicationDataContainer
6262
private readonly SemaphoreSlim mutex = new SemaphoreSlim(1, 1);
6363

6464
const string STORAGE_NAME = "AppStorage.data";
65-
IFile storageFile = null;
65+
string storageFileName = null;
6666

6767
public ApplicationDataContainer(string name = STORAGE_NAME)
6868
{
69-
storageFile = FileSystem.Current.LocalStorage.CreateFileAsync(name, CreationCollisionOption.OpenIfExists).Result;
69+
storageFileName = name;
70+
var storageFile = FileSystem.Current.LocalStorage.CreateFileAsync(storageFileName, CreationCollisionOption.OpenIfExists).Result;
7071
var data = CodePushUtils.GetJObjectFromFileAsync(storageFile).Result;
7172

7273
if (data != null)
@@ -90,14 +91,16 @@ async Task SaveAsync()
9091
{
9192
await mutex.WaitAsync().ConfigureAwait(false);
9293
var jobject = JObject.FromObject(Values);
94+
var storageFile = await FileSystem.Current.LocalStorage.CreateFileAsync(storageFileName, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
9395
await storageFile.WriteAllTextAsync(JsonConvert.SerializeObject(jobject)).ConfigureAwait(false);
9496
mutex.Release();
9597
}
9698

9799
public async Task DeleteAsync()
98100
{
99101
Values.Clear();
100-
await storageFile.DeleteAsync();
102+
var storageFile = await FileSystem.Current.LocalStorage.CreateFileAsync(storageFileName, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
103+
await storageFile.DeleteAsync().ConfigureAwait(false);
101104
}
102105
}
103106
}

0 commit comments

Comments
 (0)