Access web page after asynch callback

G

Glen

This is my first attempt as asynchronous processing. I have created a
small test app as proof of concept, but I am having one proglem. In the
example (code listed below), my callback routine has two problems:

1. It runs TWICE; and
2. While it seems to update the web page controls, the results never
show up on the page.

I am using delegates per a couple of examples I found on MSDN and
elsewhere.

What I'm trying to accomplish is to spawn an asynchronous routine from
the page. When the routine is complete, the callback routine should
update the screen to let the user know it's done.

Any help would be greatly appreciated. My code is listed below.

Sincerely,
Glen Wolinsky

--------------------------
Numbers 6:24-26
--------------------------
------------------------------------------------------------------------
-------------------------------------

Imports System.Threading

Public Class AsynchTest1

Inherits System.Web.UI.Page

Protected WithEvents btnGo As System.Web.UI.WebControls.Button
Public Delegate Function TestDelegate() As String
Dim intTemp As Integer

------Page Load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub

------Button to start process
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGo.Click
Session("StartProc") = Today.Now

Dim TestDlgt As TestDelegate = New TestDelegate(AddressOf
TestRoutine)

Dim ar As IAsyncResult = TestDlgt.BeginInvoke(New
AsyncCallback(AddressOf TestComplete), _
Nothing)

lblStatus.Text = "Procedure started..."

End Sub

-------Asynchronous Routine
Private Function TestRoutine() As String
Dim start As DateTime

SyncLock Session.SyncRoot
start = Session("StartProc")
End SyncLock

Do While (Date.Now.Ticks - start.Ticks) < 100000000
'Process this loop for a few seconds
Loop

Return "The asynchronous process is complete"
End Function


------Completion callback routine
Private Sub TestComplete(ByVal ar As IAsyncResult)
Dim ad As TestDelegate = CType(ar.AsyncState, TestDelegate)

lblStatus.Text = ad.EndInvoke(ar)
lblStatus.ForeColor = Color.Red

End Sub

End Class
 
C

Craig Burkett

Hi there,

I believe that since HTTP is designed the way it is, it is not possible to
push information out to the user subsequent to the response. This is going
to require push technology, meaning that some component sitting on the
user's machine listening for IP messages. What I would be interested in is
a component that is easily installed from the web site to the user's machine
without requiring a visit fromtech support.

Any suggestions?

Thanks,
Craig
 
G

Guest

You'll have write some javascript into your page when your thread ends, something like

Response.Write("setTimeout('window.opener.location.href=window.opener.location.href', 999);")

This should reload your window and register your new window state.

This of course works only if you use Page_Load event on your page properly.

Good luck,

Yuri Vanzine
 
C

Craig Burkett

Isn't this a one time thing? If so, wouldn't it have to be in a loop and
wouldn't it (with enough apps and users using this technique) begin to clog
the network with POST and response data (which may or may not have new data
in it)?

Do you know of a way to push the data out to the user?

Thanks,
Craig


Yuri Vanzine said:
You'll have write some javascript into your page when your thread ends, something like
Response.Write("setTimeout('window.opener.location.href=window.opener.locati
on.href', 999);")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top