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

Posted on 2011-04-26
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))

End of function

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

    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
'This function here just creates the java script.
                    strRunScriptASync &= DirectPrintLable(strIntegratedTrackingNo(rc), strCarrierSelect, DDLServiceType.SelectedValue)

            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

Question by:Bran-Damage
    LVL 17

    Expert Comment

    by:Carlos Villegas
    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
                End If 

    Open in new window


    Accepted Solution

    These did not resolve my issue.  Going another way.

    Author Closing Comment

    Wanted to just delete this post, but could not find how to quick enough.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now