title: Sqlite.net async - how use in Xamarin?
body: <p>I created an app for Android and Windows Phone. For data access i'm using sqllite.net async. I created the simple example solution with a PCL liblary, Xamarin Android project and Windows Phone 8 silverligth project. This is my DataService in PCL:</p>
  
  <pre><code>public  class DataService
  {
       private SQLiteAsyncConnection _dbConnection;
       public DataService(ISQLitePlatform platform, string path)
      {
          var connectionFactory = new Func&lt;SQLiteConnectionWithLock&gt;
                  (() =&gt; new SQLiteConnectionWithLock(platform, new     SQLiteConnectionString(path, true)));
          _dbConnection = new SQLiteAsyncConnection(connectionFactory);
      }
      public async Task Initialize()
      {
          await _dbConnection.CreateTableAsync&lt;ToDo&gt;().ContinueWith(t =&gt;
          {
             Debug.WriteLine("Create");
          });
      }
      public async Task&lt;int&gt; AddNewToDo(ToDo item)
      {
          var result = await _dbConnection.InsertAsync(item);
          return result;
      } 
  
      public async Task&lt;List&lt;ToDo&gt;&gt; GetAllToDos()
      {
          var result = await _dbConnection.Table&lt;ToDo&gt;().OrderByDescending(t =&gt; t.TimeStamp).ToListAsync();
          return result;
      }
      ....
    }
  </code></pre>
  
  <p>This is using in  Windows Phone:</p>
  
  <pre><code>    private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
      {
          var db = new DataService(new SQLitePlatformWP8(), "my.db");
          await db.Initialize();
          await db.AddNewToDo(new ToDo {Text = "Hello world"});
          var items = await db.GetAllToDos();
          Debug.WriteLine("Count - {0}",items.Count);
      } 
  </code></pre>
  
  <p>output in Windows Phone:</p>
  
  <pre><code>Create
  Count - 1
  </code></pre>
  
  <p>It is ok. Debugging is works.</p>
  
  <p>This is using in Xamarin Android:</p>
  
  <pre><code>    protected override void OnCreate(Bundle bundle)
      {
          base.OnCreate(bundle);
  
          // Set our view from the "main" layout resource
          SetContentView(Resource.Layout.Main);
  
          // Get our button from the layout resource,
          // and attach an event to it
          Button button = FindViewById&lt;Button&gt;(Resource.Id.MyButton);
  
          button.Click += delegate
          {
              TestDb();
          };
      }
  
      private async void TestDb()
      {
          string documentsPath =        System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); 
          var path = Path.Combine(documentsPath, "my.db");
          var db = new DataService(new SQLitePlatformAndroid(), path);
          await db.Initialize();
          await db.AddNewToDo(new ToDo { Text = "Hello world" });
          var items = await db.GetAllToDos();
          Console.WriteLine("count - {0}",items.Count);
      }
  </code></pre>
  
  <p>output:</p>
  
  <pre><code> [0:] 
   Create
   [0:] Create
   02-18 00:46:01.167 I/mono-stdout(19234): Create
   count - 1
   02-18 00:46:01.675 I/mono-stdout(19234): count - 1
  </code></pre>
  
  <p>Why are invoked more than once? Debugging not working. When I stop at code with await, next step just drops out of the method without touching my return calls or anything.</p>
  
  <p>This is a simple example, and I do not understand why this is happening. Maybe I'm doing something wrong.</p>