Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to use Azure, the easiest way to proceed is <a href="http://www.windowsazure.com/en-us/develop/mobile/">Windows Azure Mobile services</a>. It allows you to setup your database and webservices using a web interface in a few minutes.</p> <p>It's quite cool, allows you to add custom javascript to your web api logic, and generates json web apis. There are client Libraries for Windows 8, Windows Phone and iOS. You could easily roll your own for any http enabled frontends.</p> <p>However be aware that taking the cloud route means that your app won't work offline, (if you don't code a cache system that is. And a cache will requires a local DB.)</p> <p><strong>About the local DB</strong> You really have to possibilities: 1) A real DB in your app, like SQLite. It's available as a <a href="https://nuget.org/packages/System.Data.SQLite">Nuget package</a> but right now ARM support isn't available out of the box, nor guaranteed by the team. If you don't need arm, Go try it :)</p> <p>2) plain old file storage, like you did before. I personally often do that myself. You will however get issues when accessing it from different threads (Access Denied errors).</p> <p>When you store things in a local file, don't forget to lock the critical sections (ie when you read or write to the file) to prevent the access denied exceptions. To be sure, Incapsulate your write/read logic in a service class instance unique within your app. (Use the singleton pattern for instance, or anything equivalent).</p> <p>The lock itself, now. I imagine that you are using async await. I like this sweet thing too. But classic C# locks (using the <code>lock</code> keyword for instance) don't work with async await. (And even if it worked, blocking wouldn't be cool).</p> <p>That's why the marvellous AsyncLock comes into play. It's a lock, but which -approximately- doesn't block (you await it). </p> <pre><code>public class AsyncLock { private readonly AsyncSemaphore m_semaphore; private readonly Task&lt;Releaser&gt; m_releaser; public AsyncLock() { m_semaphore = new AsyncSemaphore(1); m_releaser = Task.FromResult(new Releaser(this)); } public Task&lt;Releaser&gt; LockAsync() { var wait = m_semaphore.WaitAsync(); return wait.IsCompleted ? m_releaser : wait.ContinueWith((_, state) =&gt; new Releaser((AsyncLock)state), this, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); } public struct Releaser : IDisposable { private readonly AsyncLock m_toRelease; internal Releaser(AsyncLock toRelease) { m_toRelease = toRelease; } public void Dispose() { if (m_toRelease != null) m_toRelease.m_semaphore.Release(); } } } public class AsyncSemaphore { private readonly static Task s_completed = Task.FromResult(true); private readonly Queue&lt;TaskCompletionSource&lt;bool&gt;&gt; m_waiters = new Queue&lt;TaskCompletionSource&lt;bool&gt;&gt;(); private int m_currentCount; public AsyncSemaphore(int initialCount) { if (initialCount &lt; 0) throw new ArgumentOutOfRangeException("initialCount"); m_currentCount = initialCount; } public Task WaitAsync() { lock (m_waiters) { if (m_currentCount &gt; 0) { --m_currentCount; return s_completed; } else { var waiter = new TaskCompletionSource&lt;bool&gt;(); m_waiters.Enqueue(waiter); return waiter.Task; } } } public void Release() { TaskCompletionSource&lt;bool&gt; toRelease = null; lock (m_waiters) { if (m_waiters.Count &gt; 0) toRelease = m_waiters.Dequeue(); else ++m_currentCount; } if (toRelease != null) toRelease.SetResult(true); } } </code></pre> <p>you can use it this way (I suppose that you have an AsyncLock field named blogLock (taken from one of my own projects):</p> <pre><code> using (await blogLock.LockAsync()) { using (var stream = await folder.OpenStreamForReadAsync(_blogFileName)) { using (var reader = new StreamReader(stream)) { var json = await reader.ReadToEndAsync(); var blog = await JsonConvert.DeserializeObjectAsync&lt;Blog&gt;(json); return blog; } } } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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