Link to home
Start Free TrialLog in
Avatar of jazzIIIlove
jazzIIIloveFlag for Sweden

asked on

progress bar on function execution C# WinForms

Hi;

I need a progress bar that is mapped to an extraction of a zip file on windows forms but for some reason, i am failing in this code.

Any help?

   private void extractZipButton_Click(object sender, EventArgs e)
        {
             ThreadPool.QueueUserWorkItem((obj) =>
    {
        ExtractZipFile(new FileInfo(Path.GetFullPath(_tomcatPath)));
            Parallel.For(0, 100, i =>
            {
             
                Invoke(new Action(() =>
                {
                    extractProgressBar.Value = (i * 100) / 10;
                }));
            });
    });

        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jazzIIIlove

ASKER

Hi;

I will check this tomorrow.

Best regards.
Hi;

Unfortunately it is not working and it crashes now. Any ideas?

Best regards
When I debug, the error is

Cross-thread operation not valid: Control 'diagnosticsTextBox' accessed from a thread other than the thread it was created on.