473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Access web page after asynch callback

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


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
3 1998
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

"Glen" <Gl**@nospam.com> wrote in message
news:uI**************@TK2MSFTNGP12.phx.gbl...
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


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 18 '05 #2
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
Nov 18 '05 #3
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" <an*******@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
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);")
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


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Barry Anderberg | last post by:
I am using asynch sockets and so I call BeginReceive and then in my callback function I have certain events that would cause me to want to throw an exception. The problem of course is that the...
18
by: Alan Z. Scharf | last post by:
1. I have a chain of six asynch callbacks initiated by a button, and want the page to refresh at the end of each callback to display A. Results of a SQLServer query showing cumulative running...
8
by: TC | last post by:
Hello, I am making an asynchronous call to a webservice and trying to update the web page with the results. The page is not updating. Does anybody know why??? Below is my code:
2
by: ghost | last post by:
As the Subject indicates I have written a web page that makes use of several web service calls. Some of the web service calls are very fast so they called synchronously. Some web service calls...
1
by: David Veeneman | last post by:
Does anyone knmow why an asynchronous worker method would crash if the e.Cancel method is set to true, but not otherwise? I'm working on a demo app with an asynchronous call, using the .NET 2.0...
4
by: Nick Gilbert | last post by:
Hi, Is it possible to access the Session of an arbitary user from an aspx page? On an e-commerce site, I am notified of payment success via a callback from the payment server to an ASPX page...
1
by: Sean | last post by:
I am looking at using delegates to perform an asynchronous call. There will be a callback invoked at the end of the call. The client thread will wait on the WaitHandle from IAsyncResult (which is...
0
by: Patino | last post by:
I have a particular WS consumer application (Windows app) that was not able to read an error from the WS app because it was calling a method asynch. The client app just hangs there. But once I...
6
by: Frank Hauptlorenz | last post by:
Hello out there, I have 2 services running. The first one runs in session mode and the 2nd not. The first one should call an operation of the 2nd one asynchronously, because this is doing some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.