WPF - Thread Ownership Error

Jun 17, 2011 at 9:10 AM
Edited Jun 17, 2011 at 9:44 AM

Error was with The UI!

 

:D stupid one anyway tnx for your great project


 

 void szc_Compressing(object sender, ProgressEventArgs e)
        {
            progress.Value += (e.PercentDelta);
        }

            public void compress(string location){
               BackgroundWorker worker = new BackgroundWorker();
                   worker.DoWork += delegate(object s, DoWorkEventArgs args)
                   {
                       SevenZip.SevenZipCompressor szc = new SevenZip.SevenZipCompressor();
                       szc.FastCompression = false;
                       szc.Compressing += new EventHandler<ProgressEventArgs>(szc_Compressing);
                       FileInfo CHECKLOCKED = new FileInfo(location);
                       if (IsFileLocked(CHECKLOCKED) == false) { szc.CompressFiles(location, files); }
                       else
                       {
                           MessageBox.Show("File is being edited by another program, please close all programs and retry.");
                       };
                   };
                   worker.RunWorkerAsync();
        }

 

Everything works fine except when program reaches 

szc_Compressing

There is an error raised: 
The calling thread cannot access this object because a different thread owns it.

I want the compressor to work as a backgroundworker while the progress is set to it's actual value.

I would be thankful if you give me a solution to get the progress value!