public async void SaveData() { var fileList = await ApplicationData.Current.LocalFolder.GetFilesAsync(); System.IO.MemoryStream ms = new System.IO.MemoryStream(); var scratchFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(localScratchFileName, CreationCollisionOption.ReplaceExisting); using (var storageTransaction = await scratchFile.OpenTransactedWriteAsync()) { using (var dw = new Windows.Storage.Streams.DataWriter(storageTransaction.Stream)) { dw.WriteInt32(Items.Count); for (int x = 0; x < Items.Count; x++) { TrackItem item = Items[x]; dw.WriteDateTime(item.Start); dw.WriteDateTime(item.End.Value); dw.WriteInt32(item.Topic.Length); dw.WriteString(item.Topic); } if (CurrentItem == null) { dw.WriteBoolean(false); } else { dw.WriteBoolean(true); dw.WriteDateTime(CurrentItem.Start); dw.WriteInt32(CurrentItem.Topic.Length); dw.WriteString(CurrentItem.Topic); } storageTransaction.Stream.Size = await dw.StoreAsync(); await storageTransaction.CommitAsync(); } } await scratchFile.RenameAsync(localFileName, NameCollisionOption.ReplaceExisting); }