Skip to main content
3 of 3
added 2115 characters in body
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60

As I said in comments, you will want to direct support issues to the bitbucket site, but my initial observation is:

You need only 1 ApiContext, typically a class field, and it should be initialized in the Loaded event of your page.

From that point, simply use the same ApiContext for all of your calls.

Also, Query methods are synchronous and must be called on another thread than that of the UI.

Update: You have indeed uncovered a bug introduced into the ApiContext.Initialize(async) code.

I have fixed this and will post new binaries within the hour.

Here is a simple example that will work with the Soapi.CS-1.0.1.3-binaries.zip when they are uploaded.

using System;
using System.Linq;
using System.Threading;
using System.Windows;
using Microsoft.Phone.Controls;
using Soapi;
using Soapi.Parameters;

namespace MarksIssue
{
    public partial class MainPage : PhoneApplicationPage
    {
        #region Fields

        private ApiContext _context;

        #endregion

        #region Constructors

        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        #endregion

        #region Private Methods

        private void _context_Initialized(object sender, EventArgs e)
        {
            // get off the ui thread
            ThreadPool.QueueUserWorkItem(delegate
                {
                    var questions = _context
                        .Official
                        .StackOverflow
                        .Questions
                        .PageSize(20)
                        .Sort(QuestionSort.Creation)
                        .Order(SortOrder.Desc)
                        .ToList();

                    // marshal results back onto the UI thread
                    Dispatcher.BeginInvoke(() => { listBox1.ItemsSource = questions.Select(q => new { q.Title }); });
                });
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            _context = new ApiContext("qgAq_KfDu0KYzlNG-qaTuw")
                .Options
                .LazyLoadingEnabled(true)
                .Context;

            _context.Initialized += _context_Initialized;
            _context.Initialize();
        }

        #endregion

    }
}
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60