locked
ASP.NET and threading (I think?) RRS feed

  • Question

  • Hi,

    I am basically trying to plan/model a web app and i've come to a bit of a road block in terms of my model. In my web app, the user uploads several files (usually pdfs, and maximum 3 files) to my server. I have to feed these files to a third party system to do some verifications/calculations, which is somewhat of a blackbox in terms my ability to alter the way it works. It takes the file(s), does some calculations, and gives me some results (the format of this I know).

    The third party system usually takes on average 1.5 to 2 mins to calculate per file and worst case scenario of maybe 3mins. I do not wish the user to be sitting on page with a busy/processing word flashing. Unfortunately I cannot even give the user some sort of quantative value of how much of the verification process has been completed while they wait.

    So, what I want to know is if there is a way that i can let this process run in the background. So that means:

    - User uploads files
    - I call a webservice from to call the third party system to start verifying/calulating in the background and write results to a DB
    - User continues with other steps in the process (which is usually greater than the time required to verify/calculate the files)
    - Just before the payment stage, check the DB to see if files have been verified and results have been written to the DB.
    - If complete, move to payment stage
    - If not display, please wait sign
    , and check intermittently (every 30s if results are ready), cap it at maximum of 5mins

    It is essential that the verification/calculation step be performed before the payment stage. I'm not sure if this is the place to ask, but i just wanted to know what are the various solutions to these sort of problems?

    I am very relatively new to asp.net (only been working with 3.5), so pardon my ignorance if this thought process seems incorrect or not very logical.

    Cheers.
    Monday, October 20, 2008 3:27 AM

All replies

  • Hi,

     

    Here is a better way to do it.

     

    - User uploads files

    - I call a webservice from to call the third party system to start verifying/calulating in the background and write results to a DB
     
    This process can be converted into a Windows Service with a Listener (please google for it) which probes a folder in your server every 1 minute or whatever. Whenever a file is found it can further with all those works you have mentioned.
     See these links that could help you:
      
    http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx
      http://msdn.microsoft.com/en-us/magazine/cc301845.aspx

     

    - User continues with other steps in the process (which is usually greater than the time required to verify/calculate the files)
     
    He is cool now. Allowed to pass-through the bottle-neck Wink

    - Just before the payment stage, check the DB to see if files have been verified and results have been written to the DB.

    - If complete, move to payment stage

    - If not display, please wait sign, and check intermittently (every 30s if results are ready), cap it at maximum of 5mins
     For checking ittermittently you can use AJAX. AJAX control toolkits are available here:
    http://www.asp.net/ajax/ajaxcontroltoolkit/


    You are certainly in the right place to pose this question and my friend you are absolutely logical Smile Good luck!!

     

    [ Prem ]
    Monday, October 20, 2008 6:35 AM
  • One thing you need to take care while designing for the asynchronous processing is the error handling.  In this scenario, if the user logs out or if the connection is lost how the error is going to be handled. 

     

    Don't assume that the user is connected till the job is completed.  When the user uploads the file, generate a unique id and give it to the user.  Store the unique id, user id, date and time of upload, file name and other relevant attributes to a table.  Add a column viz. status where you can maintain the status of the file.  If there is an error, the same can be added to the table.  When the user connects again, you can show the errors or you can allow the user to check based on the unique ids generated for him. 

     

    The status flag can be checked from a Ajax control to give the update to the user, if he/she still connected.

    Monday, October 20, 2008 8:47 AM