Launching a long-running process asynchronously

后端 未结 1 1390
名媛妹妹
名媛妹妹 2021-01-21 00:47

In our web application, a user can make a change that requires a lot of database tables to update. The load time for all that can be up to 30 seconds. I don\'t want the user to

相关标签:
1条回答
  • 2021-01-21 01:17

    You shouldn't really execute a long-running process in a web page context; the HTTP Request/Response model is not favourable to that concept when the client application is a web browser. This is a scenario I have had to address a number of times; you could: -

    1. use MSMQ; submit a message to a queue containing details of the operation to be performed, or
    2. write the details of the operation to be performed to a "Jobs" table

    You can then create a Windows Service to read messages from the queue/pull un-processed items one at a time from the table, and perform the long-running operation.

    In the most recent project I had to do this, from memory, I created a usercontrol that sat in the header (i.e. in the masterpage) which polled the database table via jQuery Ajax once every 15 seconds to detect when the job was completed, and show a popup to the user indicating the job was finished.

    I can try and dig out some examples somewhere but those are the main moving parts, does that help at all ?

    0 讨论(0)
提交回复
热议问题