Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello experts,

I am new to javascripts

please help me to solve this,

I have a function for db trip. that fires on every 10 mili seconds. problem is data is varying some time it gives 3 records sometime 5 records. there is not an issue of sp parameters I have passed. I think it's due to the function call which is not a thread. so process of function call is overlapping before the previous call complete

I have seen article for multi threading
https://gist.github.com/johdax/1269740[^]

but don't have idea to integrate my function with threading.


this is my function
C#
<script>
	setInterval(function(){UserList()},10);


function UserList()
        {
            if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp6=new XMLHttpRequest();
            }
            else
            {// code for IE6, IE5
                xmlhttp6=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp6.onreadystatechange=function()
            {
                if (xmlhttp6.readyState==4 && xmlhttp6.status==200)
                {
                    $("#UserStatusList").html(xmlhttp6.responseText);
                }
            }
            var a = $('#cmbProjectList').val();
            if (a==null){  a=""}

            xmlhttp6.open("GET","UserList.asp?ProjectId=" +  a,true);
            xmlhttp6.send();
            return false;
        }
</script>


please help me to solve this.
how can I apply threading on this?
Posted

1 solution

JavaScript is a single-threaded environment, meaning multiple scripts cannot run at the same time. For solving this issue in we can you a web worker. Web Worker defines an API for running scripts in the background independently of any user interface scripts. It will Run in an Web Workers run in an isolated thread. You can get more data about this from http://www.html5rocks.com/en/tutorials/workers/basics/[^]

You can get Help about calling service calls inside web working from my blog:
http://mobilejquery.wordpress.com/2013/05/20/ajax-call-with-web-worker/[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900