Note that there are some explanatory texts on larger screens.

plurals
  1. POLocal Storage - WIn 8 C#
    primarykey
    data
    text
    <p>I have a published app in Windows Phone store and I'm porting the app to windows 8. There are set of values that needs to be saved persistently.. The smaller values(few counts, few settings) I'm saving in the ApplicationDataContainer. I have a datetime array that I need to save. But every time the user enters a date I'm saving that date into an array. The array is then written to a text file.</p> <p>Since I cant find a single exit of the app like the OnBackKeyPress in WP, I'm writing the the array to the file as soon as the user is entering the date. So when the user continuously enters dates, it opens file, write array each time.. When the user opens the app, it reads it from the file and updates the UI according to the dates. </p> <p>Now the problem is.. Suppose you continously enter dates, then close the app quickly and when you open it next time, only few dates are saved.. rest of the dates have junk values. But the file writing is properly done when im debugging using break points.. It also works when I give a time gap of about 1 or 2 seconds before I enter the next date.</p> <p>Is it because that when not debugging, the UI load is faster? And since the background file writing is not yet finished it jus gets terminated.?? How do I solve this? I do I save the array of dates?</p> <p><strong>EDIT</strong></p> <p>This is how I write to file. I have included a flushasync :(</p> <pre><code> public async Task&lt;bool&gt; WriteHistoryToFile() { bool fileWrite = false; if (m_iHistCount &gt; 0) { try { StorageFile sampleFile = await localfolder.CreateFileAsync("HistoryFile", CreationCollisionOption.ReplaceExisting); var stream = await sampleFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite); using (var outputStream = stream.GetOutputStreamAt(0)) { DataWriter dataWriter = new DataWriter(outputStream); for (int i = 0; i &lt; m_iHistCount; i++) dataWriter.WriteString(m_dtHistory[i].ToString("d", CultureInfo.InvariantCulture) + "`~"); await dataWriter.StoreAsync(); await dataWriter.FlushAsync(); dataWriter.Dispose(); await outputStream.FlushAsync(); fileWrite = true; } } catch (Exception e) { string str = e.Message; fileWrite = false; } return fileWrite; } else { return fileWrite; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload