簡體   English   中英

從VBScript使用BackgroundWorker

[英]Using BackgroundWorker from VBScript

我創建了這樣的代碼以使用另一個類中的BackgroundWorker:

    public void BackgroundWorkerTest()
    {
        BackgroundWorker bw = new BackgroundWorker();

        bw.WorkerReportsProgress = true;
        bw.WorkerSupportsCancellation = false;
        bw.DoWork += new DoWorkEventHandler(DoWork);
        bw.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged);
        bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RunWorkerCompleted);
        bw.RunWorkerAsync();
        while (bw.IsBusy) 
            System.Threading.Thread.Sleep(50);
    }

    private void DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;

        string connStr = "<conn_str>";
        string path = "";
        MyClass.StaticMethod(string1, string2, worker);
    }

    private void ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        int progress = e.ProgressPercentage;
        string message = e.UserState.ToString();
    }

    private void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        string progress = "Done.";
    }

從我的MyClass.StaticMethod()

    worker.ReportProgress(percents, message);

發送進度信息。 是否可以在VBScript中使用以上代碼(在BackgroundWorkerTest()方法中提及)或類似代碼? 必須從VBScript(在InstallShield中)輸出進度信息。 它是否具有足夠的功能?

如果您使用的是基於MSI的InstallShield項目類型,請使用Google Windows Installer XML(WiX)部署工具基礎(DTF)。 DTF是一個SDK,用於創建要在MSI內部運行的托管代碼自定義操作。

如果您使用的是InstallScript項目類型,請使用Google DotNetCoCreateObject(InstallScript函數)。

無論如何,我建議您確保不要重新發明輪子。 (我看到了您對連接字符串的引用。)

暫無
暫無

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

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