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 7639225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:21:56+00:00 2026-05-31T08:21:56+00:00

I’m using reactive extensions in my wp7 app that I’m making and I wish

  • 0

I’m using reactive extensions in my wp7 app that I’m making and I wish to get the the current location at certain intervals (intervals are based on a user setting). For this example lets say after every 5 seconds I wish to know the current location from the GeoCoordinateWatcher.

I have read some places that I can use .Delay(5 Seconds) but wouldn’t that just delay the stream of position changes? As I am only after the current position, would .Delay(5 seconds).Last() work for what I want?

My code so far

if (LocationServices == null)
     LocationServices = new GeoCoordinateWatcher(GeoPositionAccuracy.High)
     {
        MovementThreshold = 2
     };

// Take the first ready status from the GeoCoordinateWatcher
var status = (from o in Observable.FromEvent<GeoPositionStatusChangedEventArgs>                  LocationServices, "StatusChanged")
              where o.EventArgs.Status == GeoPositionStatus.Ready
              select o);

status.Subscribe();

var pos = (from s in status
           from p in Observable.FromEvent<GeoPositionChangedEventArgs<GeoCoordinate>>(LocationServices, "PositionChanged")
           select p.EventArgs.Position); // Do something here to delay?

        pos.Subscribe(LastPos =>
        {
            // Do something with LastPos
        }
        );

        LocationServices.Start();

I’m thinking something like this would work?

var pos = (from s in status
           from p in Observable.FromEvent<GeoPositionChangedEventArgs<GeoCoordinate>>(LocationServices, "PositionChanged")
           select p.EventArgs.Position).Delay( var pos = (from s in status
                   from p in Observable.FromEvent<GeoPositionChangedEventArgs<GeoCoordinate>>(LocationServices, "PositionChanged")
                   select p.EventArgs.Position).TakeLast(1).Delay(new TimeSpan(0,0,5));

        pos.Subscribe(Lastpos =>
        {
           // Do something with Lastpos 
        }
        );;           

Edit: Nope it doesn’t work

  • 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-31T08:21:57+00:00Added an answer on May 31, 2026 at 8:21 am

    There are a few different rate limiting operators in RX. Sample is the closest to what you describe, but it will not generate a notification every 5 seconds if the source is not producing new notifications (in other words: Sample = “no more often than”).

    You should be able to get a polling effect by combining a few other operators. To start, we will need Interval to get the ticks and CombineLatest to do the sampling at the ticks. However, CombineLatest will output a result both on ticks and notifications from the original source. To deal with that, we can use a combination of Scan, Where and Select. In the end you should have something like:

    IObservable<T> Poll<T>(this IObservable<T> source, TimeSpan interval)
    {
        //error checking goes here
        return source.CombineLatest(Observable.Interval(interval),
                                    Tuple.Create)
                     .Scan(Tuple.Create(string.Empty, -1L, -1L),
                           (a, t) => Tuple.Create(t.Item1, t.Item2, a.Item2))
                     .Where(t => t.Item2 != t.Item3)
                     .Select(t => t.Item1);
    }
    

    A few notes about the code you posted:

    var pos = (from s in status
               from p in Observable.FromEvent<GeoPositionChangedEventArgs<GeoCoordinate>>(LocationServices, "PositionChanged")
               select p.EventArgs.Position);
    

    This makes a new subscription to the PositionChanged event every time the status event is triggered as ready. This will eventually cause position changes to be reported multiple times, which is probably not what you want. You probably want something more like:

    var status = Observable.FromEvent<...>(LocationServices, "StatusChanged");
    var readys = status.Where(o => o.EventArgs.Status == GeoPositionStatus.Ready);
    var notReadys = status.Where(o => o.EventArgs.Status != GeoPositionStatus.Ready);
    var positions = Observable.FromEvent<...>)(LocationServices, "PositionChanged");
    
    var readyPositions = from r in readys
                         from p in positions.TakeUntil(notReadys)
                         select p;
    //now you can use the Poll operator
    readyPositions = readyPositions.Poll(TimeSpan.FromSeconds(5));
    

    EDIT Upon further review, if all you want to do is poll the position every so often, there is no need to handle either event. You can simply check the properties on a timer.

    var readyPositions = from tick in Observable.Interval(TimeSpan.FromSeconds(5))
                         where LocationServices.Status == GeoPositionStatus.Ready
                         select LocationServices.Position;
    

    If you only want the timer to run while the watcher is “Ready”, you can use the status event, but still don’t need to use the position event.

    //using variable definitions from above (readys, notReadys)
    var readyPositions = from r in readys
                         from i in Observable.Interval(TimeSpan.FromSeconds(5))
                                             .TakeUnitl(notReadys)
                         select LocationServices.Position;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.