问题
I have a Web API built in ASPNET Web API application that has a Method that runs a lot of processes, like follows:
- File processed
- Inserting records to DB
- Applying rules to records
- Validating results
I would like to have a RealTime feedback from my server to my client in order to know what is the actual process that is being executed.
I would like something like the Dropbox upload screen:
I was reading that SignalR is a library for building RealTime applications.
Any clue or sample on how can I implement such functionality?
回答1:
SignalR can update your progress bars and indicators when it gets something back from the service, but as you said, you have one method which runs four different stages and you want to know when each state is completed. A SignalR Hub can't hook into your method and report on each call inside it being executed to the best of my knowledge.
What might solve your problem would be combining SignalR with a duplex service. The duplex service can issue a callback to your client after each stage is complete, SignalR can catch it, and update your client's UI, moving said progress bar along.
来源:https://stackoverflow.com/questions/22993190/how-to-get-feedback-from-a-web-api-process-in-order-to-update-front-end