Click here to Skip to main content
13,143,708 members (29,282 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I would like to understand how would it be possible to use threads with bing maps.
The task at hand is that of making a polygon (shape) blink and at the same time keep the browser responding for the user to navigate through the map.

At my attempt to make the polygon blink (using client side code [now I know that javascript is single threaded but I still can't figure out a solution]), I ended up freezing the whole browser.

Thanks for any help guys,
Posted 22-Jan-13 11:18am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

For a proper answer, you'd have to post what code you're using already. However, in general, you can avoid freezing the UI by using setTimeout, which you can read about here:

Basically, do a small bit of work, then call setTimeout so the UI can take control for a few milliseconds before you resume doing more work. Repeat that and you can simulate multiple threads.

EDIT: Here's an example (a number will increment every 30 milliseconds using a timeout rather than a loop):
  <div id="info">0</div>
  <script type="text/javascript">
    // Do not pollute the global scope.
    (function() {
      var val = 0;
      var fnRepeat;
      fnRepeat = function() {
        val = val + 1;
        var infoElement = document.getElementById("info");
        setTimeout(fnRepeat, 30);

The same concept can be applied for any operation you would typically perform in a loop.
Jukatzu 22-Jan-13 17:56pm
Thanks for the quick reply Sir.

I do not wish to include any code since this is a personal project. However, for you to understand me better, let me give an identical scenario. Let's say I want to make a circle move continuously on the map along the x-axis. At the same time I want to be able to travel around the world with my cursor and zoom, pan...whatever. If I put in a while loop for the circle to keep moving left, how would I be able to re-gain control over the map at the same time? I have seen the link you gave me, but that speaks of one process waiting for the other, whereas in my case I do not wish to wait. One process has to run infinitely whilst the other allows user control in real-time. Hopes this explains better.

Thanks again for your time!
AspDotNetDev 22-Jan-13 18:18pm
I updated my answer to show you an example.
Jukatzu 22-Jan-13 18:23pm
Thank you! I will apply it to my case and see what happens. I can see what you mean better now. Will get back to you soon.

Much obliged.
Jukatzu 23-Jan-13 18:36pm
Worked exactly as intended.
Should have thought of using the function recursively stupid me.
However I am very grateful for your help.
AspDotNetDev 23-Jan-13 19:12pm
I'm glad to hear it worked for you :-)
Jukatzu 25-Jan-13 8:56am
Sir, is it normal that the setTimeout function deteriorates after some time? In the sense that at first the map is very responsive, and the more time goes by with the setTimeout running, the less responsive the map becomes until you are not able to move it. The code in the setTimeout function continues smoothly though. I was expecting the performance to be the same throughtout and not deteriorate exponentially by time. Am I missing something?
AspDotNetDev 25-Jan-13 12:14pm
I have no idea. Post a new question about your issue and make sure to include some sample code. Make sure to include only the relevant code so your sample is as small as possible.
Jukatzu 25-Jan-13 17:33pm
Solved it myself. Was re-creating a circle from another function every timeout so the browser was not capable of finishing before the next run; setting it back by a bit each time ;) Thanks sir
AspDotNetDev 25-Jan-13 18:43pm
Awesome :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100