Implementing long running search in ASP.NET
I am building a search page in asp.net 3.5. Search takes a bit of ti开发者_运维问答me (few seconds to few minutes). Current I use AsyncMethodCaller to call Search method. AsyncMethodCaller method stores search results in Session. I user Ajax timer to check if Search method finished and then display results.
What would be the best way to implement this scenario?
I would use a Page Method from the ASP.NET Ajax Framework. It's easy to call them async and you have a callback when it's done.
Have a look here. (Async is explained at the commens of the post)
You could try the reactive extensions for .NET . I haven't tried them yet, but looks promising.
That seems perfectly fine to me, or have I missed the point of the question?
I did a similar thing recently in a PHP front-end with a search that takes about 30 seconds.
I implemented the actual search logic as a console application. The web service calls the console application to carry out the search and records the process ID of the application handling the search in the session.
An AJAX timer in the front-end polls the server every second, which checks if that process ID is still running. If it's finished, it looks in the database (where the application writes the results) and sends those back to the front-end.
If Javascript is disabled, a simple meta refresh does the same thing.
精彩评论