httphandler polling RRS feed

  • Question

  • User653763465 posted


     I need to write an httphandler that accepts a file via a multi-part/form-data post, inserts a record into a database for it (to log that our app has gotten the file), and saves the file to a local file system.  At this point, an existing, COM+ based legacy windows vb6 app that runs on another server will have been polling that table for a new record to see if we got a new file, will then see the database record for the new file and know to do some processing of the data in that file, and then update a status field on the database record to indicate it has been processed, and put a message in a message field on that record to indicate a specific response to that kind of file processing.  The problem is, I somehow need my handler to be able to know that the processing is done, so it can return some data in the response to the user who has done the post.  The only thing I can think of doing so far is to just make the handler wait for a fixed amount of time (so as not to infinitely wait), and keep polling the database every couple seconds to see if the status was updated on that record and when it finds it has, extract the message from that record and send it back to in the http response.  This also means making the handler wait by calling thread.sleep(2000) and then polling the database in a while loop until it finds the status it wants from the record.  Is there a better way out there to do this??  Thanks!!

    Friday, March 27, 2009 2:29 PM

All replies

  • User1622957740 posted

    One way to do this is via AJAX. You can accept the upload as you are doing now (if it's not taking too long - otherwise you'd want this done via AJAX as well). Return from the call and hten immediately upon return fire another request from the client side page that polls to see if the request is done and repeat every few seconds (or however frequently).

    This way you're not tying up a server thread permanently and you can just poll the data base within the callback handler on the server. When the operation is complete you can then send a message back to the client and either return a message or a link to another page that lets you download some generated data that depends on complete data of the external process.

     So there are 3  server pieces:

    • Upload handler
    • Ajax Callback  handler (AreYouDoneYet Pings)
    • Results Page (Get and display the result data)

    +++ Rick ---

    Saturday, March 28, 2009 10:29 PM