Thursday, March 22, 2012

Thread & timer in Web application C#

Hi all,I am using web application to request some infomation to the validgateway and get the response. But in some time if we request theinvalid gateway it wont response. So the application does not doanything without the response. So I planned to use the thread and timerconcept. If I put the function in thread and used the timer concept. Inthe windows application i did the same using the thread and the timertick. I dont know how to implement in the web application. If anybodyknows please give me ur suggestions.

Hi,

You might get some idea from here,

http://ajax.asp.net/docs/overview/UsingTimerControlTutorial.aspxhttp://www.codeplex.com/AtlasControlToolkit/Release/ProjectReleases.aspx?ReleaseId=1813http://www.codeproject.com/Ajax/stoppabletimer.asphttp://www.codeproject.com/useritems/WebTimer.asp http://www.codeproject.com/aspnet/dhtml_timer.asp


use ajax....

<script>

var xmlHttp

function showHint()

{

//var url="concession/AJAX_Code.aspx"

var url="timeservice.asmx/HelloWorld"

xmlHttp=GetXmlHttpObject(stateChanged)

xmlHttp.open("post", url ,true)

xmlHttp.send(null)

window.setTimeout("showHint()",1000);

}

function stateChanged()

{

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

{

document.getElementById("lblDate").innerHTML=xmlHttp.responseText

}

}

function GetXmlHttpObject(handler)

{

var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)

{

alert("This example doesn't work in Opera")return

}

if (navigator.userAgent.indexOf("MSIE")>=0)

{

var strName="Msxml2.XMLHTTP"

if (navigator.appVersion.indexOf("MSIE 5.5")>=0)

{

strName="Microsoft.XMLHTTP"

}

try

{

objXmlHttp=new ActiveXObject(strName)

objXmlHttp.onreadystatechange=handler

return objXmlHttp

}

catch(e)

{

alert("Error. Scripting for ActiveX might be disabled")return

}

}

if (navigator.userAgent.indexOf("Mozilla")>=0)

{

objXmlHttp=new XMLHttpRequest()

objXmlHttp.onload=handler

objXmlHttp.onerror=handler

return objXmlHttp

}

}

</script>

//////////////And the webservice for this is

<WebMethod()> _

PublicFunction HelloWorld()AsString

Return Now.ToString("dd-MMMM-yyyy hh:mm:ss")

EndFunction

0 comments:

Post a Comment