Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试从线程更新wpf控件时,应用程序挂起_C#_Wpf_Multithreading - Fatal编程技术网

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

C# 尝试从线程更新wpf控件时,应用程序挂起,c#,wpf,multithreading,C#,Wpf,Multithreading,我的应用程序挂起在这一行this.SFprogress.Value=20;//这是一个进度条,它不会在visual studio上引发任何错误 我只是尝试在SalesForceExporter类中每次引发事件“RecordPosted”时更新进度条。我是一个新的线程wpf,我很难办这一点,任何帮助将不胜感激 { var export = new SalesForceExporter(ItemsSource); export.RecordPosted += exp

我的应用程序挂起在这一行
this.SFprogress.Value=20;//这是一个进度条
,它不会在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
            }));
        }
{
var export=新的SalesForceExporter(ItemsSource);
export.RecordPosted+=export\u RecordPosted;
Thread oThread=新线程(newthreadstart(export.export));
oThread.IsBackground=true;
oThread.Start();
}
void export_RecordPosted(对象发送方,RecordPostEventArgs e)
{
UpdateProgress(如RecordNumber,如BatchSize);
}
私有void UpdateProgress(int currentcount,int totalCount)
{
如果(总计数>0)
{
//调用((操作)((x,y)=>{SFprogress.Value=100d;})、currentcount、totalCount);
this.Dispatcher.Invoke(DispatcherPriority.Normal),新操作(delegate())
{
this.SFprogress.Value=20;//这是一个进度条
}));
}

使用BeginInvoke,然后再试一次。如果没有帮助,那么您需要发布一个主线程堆栈跟踪。为什么不将其作为答案发布,以便我可以选择它!这很有效,非常感谢!因为我不知道它为什么有效。很公平,无论如何,谢谢您。