ASP.NET check thread status on long thread start?

I have a situation where a user is asking to complete a long process. I am planning to run it in another encoded thread and return a message to the user "processing". Then every couple of seconds or so I will poll (via an asynchronous call) the thread for my status. When the thread is running, I want to show a success message.

The question is, how can I poll the thread after the initial request completes?

As I understand it, the page object will allocate a separate thread. When the request is complete, the page object no longer exists ... but what about this thread? How do I get the status of this thread that I have created?

0


a source to share


2 answers


Well, you need to identify the request in some way. If you want to be able to scale it across multiple computers, you should look at storing the request id and current state in the database (or some kind of repository with the same access from anywhere).

If you don’t care about this situation, and you don’t worry about disposing of the AppDomain, you can just add the singlet dictionary from the request id to the status - but consider making it automatically reset itself after some period if the client just goes and does not check status.



(Of course, it doesn't have to be a real singleton - it could be some kind of shared resource exposed through dependency injection, but the point is, it needs to be shared in some way so you can get a new request from it.)

You can also use an object with support for session - again with reservations about the multiserver web sites and AppDomain

.

+3


a source


I disagree with John's answer. You don't need a way to identify the request, you need a way to uniquely identify the thread that your request created. Then your ajax request to poll the thread can check that Thread has finished executing. I don't understand why the original request matters ...



0


a source







All Articles