Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

Im trying to simply get all of the recent questions using Windows Phone 7.

But I keep getting an ObjectDisposedException

My Code is not complicated:

public void BeginGetAllRecentQuestions()
    {
        _context.Options.LazyLoadingEnabled(true);
        _context.Initialized += ContextInitialised;
        _context.Initialize(true);
    }

private void ContextInitialised(object sender, EventArgs e)
    {
        QuestionsQuery questionsQuery = _context.Official.StackOverflow.Questions.PageSize(20);
        if (GotAllRecentQuestions != null)
            GotAllRecentQuestions(questionsQuery.Sort(QuestionSort.Creation).Order(SortOrder.Desc).ToList());
    }

private void QuestionsReceived(List<Question> questions)
    {
        Debug.WriteLine(questions.Count);
        this.RecentQuestions = questions;
    }

And thats it, but I keep getting the exception, with the stack trace:

at System.Threading.EventWaitHandle.Set() at Soapi.ApiContext.<>c_DisplayClass12.b_e(IAsyncResult a) at System.Net.Browser.ClientHttpWebRequest.<>c_DisplayClassd.b_b(Object state2) at System.Threading.ThreadPool.WorkItem.doWork(Object o) at System.Threading.Timer.ring()

which means nothing to me...

any ideas?

share|improve this question
    
Mark - support for Soapi.CS is @ bitbucket.org/bitpusher/soapi.cs/issues. This post is likely to garner negative attention from mods and others. Go ahead and post it there with some more details and I will help you figure it out. –  Sky Sanders Sep 16 '10 at 7:05
2  
ok, sorry about that, but really a down vote? –  Mark Sep 16 '10 at 9:22
    
ok - try the code below with the 1.0.1.3 binaries bitbucket.org/bitpusher/soapi.cs/downloads - thanks for the bug –  Sky Sanders Sep 16 '10 at 11:20
    
expect things like that, mark, but don't let it bother you. apparently the friendly suggestion of the first comment was not enough for them and they wanted to spank you. ;-) –  Sky Sanders Sep 16 '10 at 13:50
add comment

2 Answers 2

up vote 1 down vote accepted

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

    }
}
share|improve this answer
1  
thanks for the fast turnaround on the bug :) –  Mark Sep 16 '10 at 9:23
    
@mark ok - try the code below with the 1.0.1.3 binaries bitbucket.org/bitpusher/soapi.cs/downloads –  Sky Sanders Sep 16 '10 at 11:28
    
Thanks again Sky, great library idea by the way :) –  Mark Sep 16 '10 at 11:31
    
@mark - my pleasure. –  Sky Sanders Sep 16 '10 at 14:09
    
Would this sample work if you didn't select the Title property and therefore create a list of String objects but instead set the ItemsSource to a list of Question objects and databind to the Title property? –  masenkablast Nov 1 '10 at 21:40
add comment

The To List Call does not work in windows phone 7 dev environment

share|improve this answer
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .