BeginInvoke

B

Brian Linden

I have a page that I need to serve ASAP, but I also have some stats to take
care of on the database side.

The execution of the stats should not effect the delivery of the page....
Is there anything wrong with doing something like this:

------------------------------------------------------------------------
Private Delegate Sub UpdateStats(ByVal param1 as integer)

Sub PageLoad(...)

Dim oUpdate As New UpdateStats(AddressOf UpdateTheStats)
oUpdate.BeginInvoke(param1, Nothing, Nothing)

'Finish the rest of the page

End Sub


Private Sub UpdateTheStats(ByVal param1 as integer)
Try
'Update the database
Catch ex as Exception
'Handle errors
End Try
End Sub
 
J

John Saunders

Brian Linden said:
I have a page that I need to serve ASAP, but I also have some stats to take
care of on the database side.

The execution of the stats should not effect the delivery of the page....
Is there anything wrong with doing something like this:
------------------------------------------------------------------------
Private Delegate Sub UpdateStats(ByVal param1 as integer)

Sub PageLoad(...)

Dim oUpdate As New UpdateStats(AddressOf UpdateTheStats)
oUpdate.BeginInvoke(param1, Nothing, Nothing)

'Finish the rest of the page

End Sub


Private Sub UpdateTheStats(ByVal param1 as integer)
Try
'Update the database
Catch ex as Exception
'Handle errors
End Try
End Sub
------------------------------------------------------------------------

Am I correct in thinking that this will just spawn off a new thread to
take
care of the stats?
Are there any limitations or other things that I should consider.

That will spawn off a new thread, but you should keep in mind that the
request which spawned that thread will probably be over before the thread
completes. When that happens, all data about the request will be destroyed.

Now, if your thread doesn't refer to anything from the Context or Page
objects, then you'll be ok. For instance, you could pass a DataSet to your
thread and use it to update the database. But your thread should not try to
access such a DataSet from Session state, for instance.

John Saunders
 
B

Brian Linden

I did figure that out....I was referencing the Request object and that kept
erroring out.

Now I just pass in everything as parameters, and everything works fine.
I just needed some re-assurance.

Thanks.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top