We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

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

Medium Priority
225 Views
Last Modified: 2012-05-11
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

Comment
Watch Question

Carlos VillegasFull Stack .NET Developer

Commented:
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

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Wanted to just delete this post, but could not find how to quick enough.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.