Hi All,
I am trying to make aound 20,000 enteries to an sql db table through a web form. Once I have clicked the page is timed out although at the backnd requets continues untill it is completed. I have thought and need expert opinion on that plesae.
Suppose on button clik there is code:
while true
--
create cards
--
end while
and how about if after the end while I have statement
response.redirect("progress.aspx")
would the page be moved to progres.aspx (which refreeses every 5 seconds) and creation would continue at the backend?
If it works then on progress page load event I would count the card creation until the count gives me exact number and have it refired o fisih.aspx
Thanks in advance and looking forwrad to hear from you people.
Regards,
Usman Ghani
What you're looking for is a way to do an asynchronous operation. You could do something like:
When someone clicks the button to create cards, you spawn a new thread and have that thread go to a sub that does the database insertions. That will free up the current thread to go back to finishing loading the UI. Also, as part of the page load, you're always looking in some place in the database for a record to indicate that it was completed. It's not really an optimal solution, but it's not that bad.
You could get fancy, and have the sub that checks to see if the cards are done get a count of the total amount completed. Anytime the page loads, it does a tally to see the status.
Be careful of creating threads too often if this is a server application. The runtime is better at thread allocation than we are; an asychronous page would be a smarter idea. And make sure any selections on a table with that much activity have the nolock hint.
|||
Hi
Here is a sample code to start a thread:
Public Sub SomeLongMethod_Thread()'first, declare a new Thread, passing the constructor the address 'of SomeLongMethod. NOTE: SomeLongMethod can be replaced with your 'own methodDim NewThreadAs Thread =New _ Thread(AddressOf SomeLongMethod)'next we set the priority of our thread to lowest, setting 'the priority to a higher level can cause unexpected results.NewThread.Priority = ThreadPriority.Lowest'finally we start the thread executingNewThread.Start()End Sub
Pls refer toThreading in ASP.NETfor details.