如何在处理时间长时 vb.net asp.net 显示进度条

本文关键字:net asp 显示 vb 处理 时间 | 更新日期: 2023-09-27 18:31:31

我有一个SQL存储过程,它可以在不到3秒的时间内获取一个mbd文件并使用自身导入它,但由于共享服务器的安全性,我不能再这样做了,但我可以使用 vb.net 将必要的临时表导入SQL服务器并继续该过程
不幸的是,完成该过程需要很长时间(3兆字节mdb文件大约需要3分钟), 我需要向客户展示流程,以便客户可以耐心等待并知道流程已经走了多远。
我已经看到了很多与此相关的事情,但它们都显示图像加载而不是确切的进度条,
我的问题是:有没有可能的方法可以在基于过程如何运行时显示进度条?
PS:我可以将节目进度百分比放在 vb.net 的 for 循环中。

编辑:具体来说,我只需要知道如何向客户端显示进度,然后更新html中的进度条,或者更改进度条宽度样式?

谢谢

如何在处理时间长时 vb.net asp.net 显示进度条

您可以使用

BackGroundWorker

使用后台工作线程时,使用@Keith模板总是很方便

BackgroundWorker bw = new BackgroundWorker { WorkerReportsProgress = true };
bw.DoWork += (sender, e) => 
   {
       //what happens here must not touch the form
       //as it's in a different thread
       //Here you should call the function that does the heavy, slow work.
       //pass the BackgroundWorker instance (bw) as an argument
   };
bw.ProgressChanged += ( sender, e ) =>
   {
       //update progress bars here
   };
bw.RunWorkerCompleted += (sender, e) => 
   {
       //now you're back in the UI thread you can update the form
       //remember to dispose of bw now
   };
worker.RunWorkerAsync();

在函数中,使用以下内容更新进度:

    void YourFunction(BackgroundWorker bw)
    {
        for (int i = 0; i < length; i++)
        {
            //do your work
            int percent = (i / length) * 100;
            bw.ReportProgress(percent);
        }
    }