On a click event I have some codes that takes about 4 seconds before the user can be redirected.
Is there a way that I can redirect the user, and the code will still be executed on the server? I
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can start a background thread (or a task on the thread pool) and redirect the user in the meantime. However, there’s no guarantee that the task will have completed by the time the redirected request arrives. Do you need it to? Is it just “tidying up” or is it an action which needs to finish processing before you can display the results?
Note that I don’t think there’s anything to stop the
AppDomainfrom being garbage collected while the thread is doing its thing… you may want to separate the long-running task into a separate service – fire off a request to that service, then redirect the user. If you have the concept of an ID for the request, you could include that in the redirect URL as a parameter, and then check whether the service has finished handling the task when the redirect request comes in.