简体   繁体   English

ASPX载入页面

[英]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? 因此,我正在学习在Visual Studios 2013上开发.aspx网站,并想了解执行可执行文件时是否可以创建“加载屏幕”?

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) 用户向您的Web应用程序发出请求以开始该过程(我假设这是您要运行并等待结果的命令行.exe
  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. 即时响应页面将包含JavaScript或<meta http-equiv="refresh" /> ,这会导致页面每10秒左右重新加载一次自身,或者向服务器发起Comet请求以接收有关该子项的通知处理完成。
  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. 当请求处理程序再次接收到请求时,它将在步骤2中执行的存储中查找该请求,并查看它是否完成,如果已经完成,则它将返回相同的“请稍候”自动刷新响应,否则它将完成该过程后,返回所需的下一页。

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);
    }
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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