0

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

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

谢谢

4

1 回答 1

1

您可以使用BackGroundWorker

在使用 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);
        }
    }
于 2013-09-17T10:25:37.943 回答