I am trying to create a program that will disable an equipment after a priod of time. To
disabled the equipment, a user would use our web application to set the time span before
the equipment would be disabled.
I first tried to accomplised this by using an AJAX method for asyncronous operation to
prevent the browser from locking up for the duration of the timespan. In addition, I
used the setTimeout method to set the time span after it has been converted to mil-second.
I understand most javascripts as well as any other programs are memory resident and the
implementation might not work (at least not consistantely) the way I planned it.
var duration = some value or (some remaining time);
function sendStopRequest(PID)
{
//alert(PID);
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
var s2 = PID.replace("tel:", "");
//var url = "http://trackfusion.gpsit.com/Alpha1/bllWebServices/webServices.asmx/StopRecorder";
var url = "../bllWebServices/webServices.asmx/StopRecorder";
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
alert(s2);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readystate == 4)
{
alert(xmlHttp.readystate);
var response = xmlHttp.responseText;
alert(response);
var XMLObject = new ActiveXObject("Microsoft.XMLDOM");
XMLObject.async = false;
try
{
XMLObject.loadXML(response);
var status = XMLObject.getElementsByTagName("int").item(0).text;
if(status == 1)
{
//alert("going to sleep");
//window.setTimeout(" ", 5000);
//getDeviceStatus(s2);
setTimeout("turnOffDevice('PID1')", duration);
}
//alert(status);
}
catch(e)
{}
}
}
xmlHttp.send('PID=' + s2);
}
After I programmed the above code, I used the
<body onunload="javascript:sendStopRequest('xxxxxxxxxxx');">
This code would allow the user to disconnect from our website
and still have the device running untill the duration value
has counted down to zero.
I do most of my development in C# but I don't know if this problem
can be resolved with C# or AJAX.