C#WPF每1秒钟更新一次文本

时间:2019-06-03 11:00:43

标签: c# wpf

我通过C#wpf表单运行msi安装程序。我想查看信息安装信息。如何显示安装信息?或者我该如何每秒更新一次文字?

例如:安装。安装...安装...

public void install_uninstall(string _targetIpAddress)
    {
        //string _targetIpAddress = (string)PC;
        string[] directum = { "1.msi", "2.msi", "3.msi" };

        string retVal = "";

        ConnectionOptions options = new ConnectionOptions();
        //options.Username = @"domain\username";
        //options.Password = "password";
        ManagementScope scope = new ManagementScope(("\\\\" + _targetIpAddress + "\\root\\cimv2"), options);
        scope.Connect();



        ManagementObjectSearcher searcher;
        SelectQuery query;
        EnumerationOptions enumOptions;
        ManagementPath p = new ManagementPath("Win32_Product");
        ManagementClass classInstance = new ManagementClass(scope, p, null);
        ManagementBaseObject inParams = classInstance.GetMethodParameters("Install");
        ManagementBaseObject outParams;
        inParams["AllUsers"] = true;
        inParams["Options"] = string.Empty;

        if (programs.Contains("1"))
        {
            thisTime = DateTime.Now;
            percent = 100 / 6F;

            Dispatcher.BeginInvoke(new ThreadStart(delegate { text_install.Document.Blocks.Add(new Paragraph(new Run(thisTime + " Удаление..."))); ProgressBar.IsIndeterminate = false; PercentText.Visibility = Visibility.Visible; }));


        thisTime = DateTime.Now;
        Dispatcher.BeginInvoke(new ThreadStart(delegate { text_install.Document.Blocks.Add(new Paragraph(new Run(thisTime + " Установка..."))); }));

        foreach (var item in dir)
        {
            inParams["PackageLocation"] = @"\\" + _targetIpAddress + @"\d$\Dir\" + item;
            outParams = classInstance.InvokeMethod("Install", inParams, null);
            retVal = outParams["ReturnValue"].ToString();

            retVal_install(dir, inParams, retVal, item);
        }
    }

1 个答案:

答案 0 :(得分:-1)

如何使用1秒钟的计时器。然后,当事件触发时,您将更新文本,请不要忘记重启计时器。我希望这个能帮上忙 :) Here is timer example