WPF ProgressBar显示问题

时间:2016-02-29 18:31:30

标签: c# wpf multithreading

显示进度条值时出现问题。我想,进度条使用其他线程来更新他的值,但它只在ParseTpSheet方法之后才能实现。我希望,你会帮助我。感谢。

namespace IntegrationPlanning.Controls
{

/// <summary>
/// Логика взаимодействия для PlaningParserControl.xaml
/// </summary>
[Serializable]
public partial class PlaningParserControl : UserControl
{
    private BackgroundWorker worker = new BackgroundWorker();
    private readonly PlaningParserModel _parserModel = new PlaningParserModel();
    public PlaningParserControl()
    {
        InitializeComponent();
        worker.WorkerReportsProgress = true;
        worker.ProgressChanged += worker_ProgressChanged;
        worker.DoWork += worker_DoWork;
    }

    void worker_DoWork(object sender, DoWorkEventArgs e)
    {
        for (var i = 0; i < 100; i++)
        {
            Thread.Sleep(150);
            worker.ReportProgress(i);
        }
    }

    void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        ParseProgressBar.Value = e.ProgressPercentage;
    }

    private void IncProgressBar(int value)
    {
        ParseProgressBar.Value += value;
    }

    private void AddFileButton_OnClick(object sender, RoutedEventArgs e)
    {
        var excelApplication = new Excel.Application();
        var openFileDialog = new OpenFileDialog {Filter = "excel files(*.xls)(*.xlsx)|*.xls;*.xlsx" };
        openFileDialog.ShowDialog();
        if (openFileDialog.FileName.EndsWith(".xls") || openFileDialog.FileName.EndsWith(".xlsx"))
        {
            ParseProgressBar.Value = 0;
            worker.RunWorkerAsync();
            _parserModel.Workbook = excelApplication.Workbooks.Add(openFileDialog.FileName);
            _parserModel.ParseTpSheet();
        }
        else
        {
            MessageBox.Show("Файл не был выбран", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information);
        }
        excelApplication.Quit();
    }
  }
}

1 个答案:

答案 0 :(得分:0)

非常感谢@Haukinger。结果代码在这里:

sca_package(compositeDir, compositeName, revision, [appHome], [oracleHome])