简体   繁体   中英

ASPX Loading Page

So I'm learning to develop .aspx websites on Visual Studios 2013 and wanted to find out if there was a way to create a "Loading screen" while I executed an executable?

The idea is the user pushes a generate button, it runs the executable and displays another page/Pop up window/etc. that will have a loading image and some text until the executable finishes. Then I want it to redirect to another page.

Whats the best way to make this happen?

Code examples are always a plus! thanks

From a high-level perspective:

  1. User makes request to your web-application to begin the process (I assume it's a command-line .exe you want to run and wait for the results)
  2. The request handler will spawn a new thread which then starts the new process and waits for the process to end. Your code will assign an arbitrary tag to this thread/process and store it somewhere. When the process finishes, the child thread will update the store to say the process finished.
  3. The request handler then returns a response to the user immediately to inform them that the process is currently running
  4. The immediate-response page will contain a JavaScript or <meta http-equiv="refresh" /> that causes the page to reload itself every 10 seconds or so, or kick-off a Comet request to the server to receive notification that the child process completed.
  5. When the request handler receives the request again, it will look it up in the store performed in step 2 and see if it's completed or not, if it has then it will return the same "please wait" auto-refreshing response, otherwise it will return the next page you want as the process is completed.

Something like this:

 // Note these fields are static so they persist between page-loads
 private static Dictionary<Int32,Boolean> _processes = new Dictionary<Int32,Boolean>();
 private static Int32 _processNum;

 ActionResult StartBackgroundTask() {

    Int32 num = _processNum++;
    _processes.Add( num, false );

    Thread thread = new Thread( delegate() {

        Process proc = new Process("MyExe.exe");
        proc.Start();
        proc.WaitForExit();

        _processes[ num ] = true; // marking as complete
    } );
    thread.Start();

    return View("BackgroundTaskIsRunning.aspx", num);
 }

 ActionResult GetBackgroundTaskState(Int32 num) {
    // Token `num` received from client.

    if( _processes[ num ] ) {
        return View("NextTask.aspx");
    } else {
        // Same view as before
        return View("BackgroundTaskIsRunning.aspx", num);
    }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM