C#

How to run my application's task on a new thread and prevent my form from freezing while doing its job?

 

            BackgroundWorker bw = new BackgroundWorker();
            bw.WorkerReportsProgress = true;
            bw.DoWork += new DoWorkEventHandler(
            delegate (object o, DoWorkEventArgs args)
            {
                    // do your work here 
            });
            bw.ProgressChanged += new ProgressChangedEventHandler(delegate (object o, ProgressChangedEventArgs args)
            {
                     progressBar1.Value = args.ProgressPercentage;
            });
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
            delegate (object o, RunWorkerCompletedEventArgs args)
            {
                if (args.Error != null)
                {
                    MessageBox.Show(args.Error.Message, "Manga Renamer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                } else {
                    MessageBox.Show("Completed", "My Application", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            });
            bw.RunWorkerAsync();

 

-