簡體   English   中英

如何在長時間處理時在vb.net asp.net中顯示進度欄

[英]how to show progress bar in vb.net asp.net while process long

我有一個SQL存儲過程,可以獲取mbd文件並在不到3秒的時間內使用自身將其導入,但是由於共享服務器的安全性,我無法再執行此操作,而是可以使用vb.net導入必要的臨時表到Sql Server並繼續該過程
不幸的是,完成該過程所需的時間太長(一個3MegaByte mdb文件大約需要3分鍾),我需要向客戶端展示該過程,以便客戶端可以耐心等待,並知道過程進行了多長時間。
我已經看到很多與此相關的東西,但是它們都顯示了圖像加載而不是確切的進度條,
我的問題是:根據流程的執行情況,是否有任何可能的方式顯示進度條?
PS:我可以在vb.net的for循環中放置顯示進度百分比。

編輯:具體來說,我只需要知道如何向客戶顯示進度,並更新html中的進度條,或者更改進度條的寬度樣式?

謝謝

您可以使用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);
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM