• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

Having a hard time getting the asynchronous post back to work the way I want it to

I have a web application that a user puts some data into some fields and then clicks the process button.

Server Side code gets executed and starts to run the process.  It makes a call to a web service and the web service returns an object that has data in it along with an image.

after it gets the object from the web service the server side code executes a lot more procedures that can take some time. This is where the problem lies.

My users need the image to print as soon as possible and do not want to wait the extra 4 - 5 seconds the rest of the process takes.

So, right now, I am creating a javascript and then registering the java script with the script manager and then once the server side code is done execute the javascript gets executed on the client side and then the javascript automatically calls a com object and passes the image to it and then the com object prints out the label.  

What I am trying to do now is create a new thread once I get the object back from the web service.  This new thread then creates the java script, registers it and then does a call back.  While the other server side code is doing the other processes.  Even doing it this way the javascript does not get executed until the server side code is done running.  

Any ideas?
global variables
Protected Delegate Sub AsyncCallDelegate()
    Private _asyncCallDelegate As AsyncCallDelegate


Web service call function

Dim t As New Thread(New ThreadStart(AddressOf ThreadForAsync))
                                    t.Start()
                                    t.Join()

End of function



  Private Sub ThreadForAsync()
        Dim task As New PageAsyncTask(New BeginEventHandler(AddressOf BeginAsyncOp), New EndEventHandler(AddressOf EndAsyncOp), New EndEventHandler(AddressOf TimedOutOp), Nothing)

        RegisterAsyncTask(task)
    End Sub

Private Function BeginAsyncOp(ByVal sender As Object, ByVal e As EventArgs, ByVal cb As AsyncCallback, ByVal state As Object) As IAsyncResult
        ' Me.Report = "Begin Async"
        _asyncCallDelegate = New AsyncCallDelegate(AddressOf AsyncCall)
        Return _asyncCallDelegate.BeginInvoke(cb, state)
    End Function

    Private Sub EndAsyncOp(ByVal ar As IAsyncResult)
        ' Report = "End Async"
        blnAsynTimeOut = False
    End Sub

    Private Sub TimedOutOp(ByVal ar As IAsyncResult)
        ' Report = "Timed Out"
        blnAsynTimeOut = True
    End Sub

    Private Sub AsyncCall()
        Dim strRunScriptASync As String = ""
        ' System.Threading.Thread.Sleep(_workTime)
        strCarrierType = objGenericCarrier.CheckCarrierType(strCarrierSelect, DDLPlantID.SelectedValue)
        If strCarrierType = Nothing Then
            strCarrierType = ""
        End If

        If strCarrierType.ToUpper = "INTEGRATED" Then
            If strIntegratedTrackingNo.Count > 0 Then

                For rc As Integer = 0 To strIntegratedTrackingNo.Count - 1
                    'Me.GVPacking.Rows(rc).Cells(4).Text
'This function here just creates the java script.
                    strRunScriptASync &= DirectPrintLable(strIntegratedTrackingNo(rc), strCarrierSelect, DDLServiceType.SelectedValue)

                Next
            End If
            If strRunScriptASync <> "" Then
                'ScriptManager.RegisterStartupScript(Me, Me.GetType(), "RunAllPopups", strRunScript, False)
                ScriptManager.RegisterStartupScript(UpdatePanelAsync, UpdatePanelAsync.GetType(), "RunAllPopups", strRunScriptASync, False)
            End If

        End If

    End Sub

Open in new window

0
Bran-Damage
Asked:
Bran-Damage
  • 2
1 Solution
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hi, what if instead of:
            If strRunScriptASync <> "" Then
                'ScriptManager.RegisterStartupScript(Me, Me.GetType(), "RunAllPopups", strRunScript, False)
                ScriptManager.RegisterStartupScript(UpdatePanelAsync, UpdatePanelAsync.GetType(), "RunAllPopups", strRunScriptASync, False)
            End If 

Open in new window

You do this:
            If strRunScriptASync <> "" Then
                 Response.Write(strRunScriptASync)
                 Response.Flush()
            End If 

Open in new window

0
 
Bran-DamageAuthor Commented:
These did not resolve my issue.  Going another way.
0
 
Bran-DamageAuthor Commented:
Wanted to just delete this post, but could not find how to quick enough.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now