Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4230948
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T01:55:04+00:00 2026-05-21T01:55:04+00:00

I’ve got an interesting issue with an app for Windows Phone 7. Right now,

  • 0

I’ve got an interesting issue with an app for Windows Phone 7.
Right now, I’m sending out some two dozen or so requests for small (a few KB) xml files to keep rapidly changing information (bus locations to be exact). I have a Timer ticking off every 10 sec to send out the requests asyncronously.

The data retreived is handled with an asynchronous callback to verify the request came back with a file, and stores the file into IsolatedStorage. When the data is needed (by the View-Model of the UI), the file is read from IsolatedStorage, parsed into internal objects (basically a GeoCoordinate and some strings) and used.

1) I’m running into the limitations of the phone’s CPU here, just a bit. If I parse all the bus data to determine which bus routes are active on the UI thread, the thread noticably slows down. I moved the work into a bakground worker like this:

public class RunningWorkerHelper
{
    public BusRouteIdModel Route { get; set; }
    public Visibility Visible { get; set; }
}

public class RunningWorker
{
    BackgroundWorker bw;
    Queue<BusRouteIdModel> workQueue;

    public RunningWorker()
    {

        bw = new BackgroundWorker();
        workQueue = new Queue<BusRouteIdModel>();

        bw.DoWork += CheckIfRunning;
        bw.RunWorkerCompleted += CheckRunningCompleted; 
    }

    public void QueueWorkItem(BusRouteIdModel route)
    {
        workQueue.Enqueue(route);
        StartWorkItem();
    }

    void StartWorkItem()
    {
        if (!bw.IsBusy && workQueue.Count > 0)
            bw.RunWorkerAsync(workQueue.Dequeue());
    }

    void CheckIfRunning(object sender, DoWorkEventArgs args)
    {
        BusRouteDataService server= BusRouteDataService.Current;
        var route = (BusRouteIdModel)args.Argument;
        if (route == null) return;

        var vehicleFile = server.GetBusVehiclesFile(route);
        var vehiclesOnRoute = RouteDataParser.ExtractBusVehicles(vehicleFile);
        var helper = new RunningWorkerHelper { Route = route };
        if (vehiclesOnRoute.Count > 0)
        {
            helper.Visible = Visibility.Visible;
        }
        else
        {
            helper.Visible = Visibility.Collapsed;
        }
        args.Result = helper;
    }

    void CheckRunningCompleted(object sender, RunWorkerCompletedEventArgs args)
    {
        var helper = (RunningWorkerHelper)args.Result;
        if (helper != null)
            helper.Route.IsRunning = helper.Visible;
        StartWorkItem();
    }

}

here’s the BusRouteIdModel (for reference)

public class BusRouteIdModel : BusRouteId, INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    Visibility _isRunning;
    /// <summary>
    /// True when there is a bus active on this route
    /// </summary>
    public Visibility IsRunning
    {
        get { return _isRunning; }
        set
        {
            if (value == _isRunning) return;
            _isRunning = value;
            OnPropertyChanged(new PropertyChangedEventArgs("IsRunnning"));
       }
    }

    /// <summary>
    /// True while path data for the route isn't available yet
    /// </summary>
    Visibility _isLoading;
    public Visibility IsLoading
    {
        get { return _isLoading; }
        set
        {
            if (value == _isLoading) return;
            _isLoading = value;
            OnPropertyChanged(new PropertyChangedEventArgs("IsLoading"));
        }
    }

    protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, args);
    }
}

public class BusRouteId
{
    public String Uid { get; set; }
    public String Name { get; set; }
}

This is data bound to a listbox element on the page (I’m using the MVVM Light Toolkit):

    public const string RouteIdsPropertyName = "RouteIds";
    private ObservableCollection<BusRouteIdModel> _routeIds = null;
    public ObservableCollection<BusRouteIdModel> RouteIds
    {
        get { return _routeIds; }
        private set
        {
            if (_routeIds == value) return;
            var oldValue = _routeIds;
            _routeIds = value;
             RaisePropertyChanged(RouteIdsPropertyName);
        }
    }

And I call my worker like this (the args.Uid id’s the bus route that got new data):

foreach (var route in RouteIds)
    if (route.Uid == args.Uid) 
        runningWorker.QueueWorkItem(route);

2) Mysteriously, the IsRunning change isn’t reflected in the UI. What did I miss?

3) How can I generalize this Queue + BackgroundWorker to handle other tasks? (I would use the Task Pool Library, but Silverlight does not have it.) I want to have a single worker so that the UI thread doesn’t get starved on the map page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T01:55:05+00:00Added an answer on May 21, 2026 at 1:55 am

    1) Not a question?

    2) IsRunning in the UI isn’t updating because of a typo:

    OnPropertyChanged(new PropertyChangedEventArgs("IsRunnning"))
    

    Too many n’s

    3) For threading like this, try ThreadPool – see http://wildermuth.com/2011/01/11/Architecting_WP7_-_Part_9_of_10_Threading

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I am writing an app with both english and french support. The app requests
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.