Async Controllers (MVC), long running process with “stops”

后端 未结 3 1468
感情败类
感情败类 2021-01-14 03:06

I\'m interested in running a long process, I want to update the UI as soon as results start coming in and not wait for it to finish.

How would I go about this? I\'ve

3条回答
  •  臣服心动
    2021-01-14 03:50

    You can run the long running task using ThreadPool.QueueUserWorkItem and it can update state in Application/Session which the user can poll. As you pointed that has some lifetime issues. Beyond what you pointed out, the app-pool could recycle - but maybe that's OK.

    What is the logical scope of that operation? Is it a system type long running task that someone/many folks need to query the progress on? Or is it a long running task on behalf of a specific user? If it's the latter, then it's OK if that user's session times out, etc... If it's the former then you need to be more durable. for example, you could store the task request, the state and the progress in a database. That way on app restart it can just pickup where it eft off and its easy to query by anyone (a noter decision point if system level task).

    The final consideration is whether you'll ever have more than one web roles (web farm/cluster). If that's ever a consideration than a DB or even separate worker role/service becomes more appropriate.

    So it all boils down to the type of task it is, who needs to monitor it and what are the durability requirements. If its just a user task, keep it simple, queueuserworkitem and session state.

提交回复
热议问题