尝试从线程更新wpf控件时应用程序挂起

时间:2013-08-08 22:57:27

标签: c# wpf multithreading

我的应用程序挂在this.SFprogress.Value = 20;// this is a progress bar这一行,并没有在visual studio上引发任何错误。

我只是在每次在SalesForceExporter类中引发事件'RecordPosted'时尝试更新进度条。我是新手来处理一个wpf而且我对此感到非常难过,任何帮助都会非常感激。

{ 
        var export = new SalesForceExporter(ItemsSource);
        export.RecordPosted += export_RecordPosted;
        Thread oThread = new Thread(new ThreadStart(export.Export));
        oThread.IsBackground = true;
        oThread.Start();

 }
       void export_RecordPosted(object sender, RecordPostEventArgs e)
    {
        UpdateProgress(e.RecordNumber, e.BatchSize);

    }

    private void UpdateProgress(int currntCount, int totalCount)
    {
        if (totalCount > 0)
        {
            //this.Dispatcher.Invoke((Action<int,int>)((x,y) => { SFprogress.Value = 100d; }),currntCount,totalCount);
            this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate()
            {
                this.SFprogress.Value = 20; // this is a progress bar
            }));
        }

0 个答案:

没有答案