How is this for server side code - is the DateTime.Now.Ticks loop for pausing ok?? I saw lots of info on the web that indicated that Thread.Sleep and what not were not good for IIS apps...
[edit]I might change it up so the MAIN loop is in the OPEN CONNECTION to the DB - no reason to loop an open/close DB connection - that seems expensive and useless...[/edit]
Code:
If ctrloption = "reportstatus" Then
Try
Dim maxloop As Integer = 20
Dim curloop As Integer = 0
Do While strMessage <> "C" And curloop < maxloop
Using dcn As New SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings("LocalSQLServerAWC").ToString)
Using cmd As New SqlCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "dbo.awc_ReportGetStatus"
cmd.Connection = dcn
cmd.CommandTimeout = 0
DetermineParameters(dcn, cmd)
cmd.Parameters("@RptId").Value = ctrlval1
dcn.Open()
strMessage = cmd.ExecuteScalar().ToString
End Using
End Using
If strMessage <> "C" Then
curloop += 1
Dim curtime As Long = DateTime.Now.Ticks
Do While DateTime.Now.Ticks < curtime + (10000 * 250) '250)
Loop
End If
Loop
.NewObject("reportstatus", "true")
.Seperate()
.NewObject("rptid", ctrlval1)
.Seperate()
Catch ex As Exception
strSuccess = ""
strMessage = ex.Message.Replace("""", "'").Replace("\", "\\")
End Try
End If
And the jQuery does this - the initial post for status...
Code:
var objReturn = $.parseJSON(msg.d);
var rptid = objReturn.rptid || "";
var queued = (objReturn.queued || "N") == "Y" ? true : false;
if (rptid.length != 0) {
if (queued) {
$(sender).find('.acs-report-status').html('Report Status: Waiting in queue...<img src="Images/ajax-loader-small.gif" />');
} else {
$(sender).find('.acs-report-status').html('Report Status: Started and running...<img src="Images/ajax-loader-small.gif" />');
}
var t = setTimeout("ctrlWebService('reportstatus', '" + rptid + "','','" + $(sender).attr('id') + "')", 1000);
//ctrlWebService('reportstatus', rptid,'',sender);
}
And in the callback after the initial POST for status
Code:
if (objReturn.message == "C") {
$("#" + strWho).find(".acs-report-status").html("Report Status: Completed");
$("#" + strWho).closest('.acs-ddreflector').removeClass("acs-report-running");
} else {
var t = setTimeout("ctrlWebService('reportstatus', '" + objReturn.rptid + "','','" + strWho + "')", 1000);
}
This is in the call back from the web service call...