title: What is the correct usage for sqlite on locking or async
body: <p>We are using Xamarin to write C# code with SQLite for android and ios. However about how to use sqlite, I seem to have a conceptual misunderstanding:</p>
  
  <p><a href="https://stackoverflow.com/questions/2493331/what-are-the-best-practices-for-sqlite-on-android">What are the best practices for SQLite on Android?</a></p>
  
  <p>According to the stackoverflow answer it says  - one helper and one db connection. Use lock around it to make sure only one thread is accessing sqlite db at any time. </p>
  
  <p>My question is - if that is the case - what is the use for async?</p>
  
  <p>I tried to use async with synchronized code - and the code gave me compile errors rightfully to avoid deadlocks.<br>
  <a href="https://stackoverflow.com/questions/7612602/why-cant-i-use-the-await-operator-within-the-body-of-a-lock-statement">Why can&#39;t I use the &#39;await&#39; operator within the body of a lock statement?</a></p>
  
  <pre><code>    public async Task InsertAsync&lt;T&gt; (T item){
          lock (mutex) {
              await asyncConnection.InsertAsync (item);
          }
      }
  
      public async Task InsertOrUpdateAsync&lt;T&gt; (T item){
          lock (mutex) {
              int count = await asyncConnection.UpdateAsync (item);
              if (0 == count) {
                  await asyncConnection.InsertAsync (item);
              }
          }
      }
  </code></pre>
  
  <p>fails. However - if I am going to use locks to ensure I am using one connection one thread at a time as a best practice in sqlite - why is there an async sqlite library at all? </p>
  
  <p>And why are some threads promoting async sqlite usage on the web.</p>
  
  <p>What is the real best practice for sqlite in android and iphone? Just using sync version? </p>