Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7951717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:38:43+00:00 2026-06-04T02:38:43+00:00

In my app I want create thousands files in background, but when I execute

  • 0

In my app I want create thousands files in background, but when I execute this it always freeze my form(after all files were created I can work with my form again). How run it properly without hanging?

private void button5_Click(object sender, EventArgs e)
    {
        BackgroundWorker bw = new BackgroundWorker();

        bw.WorkerReportsProgress = true;

        bw.DoWork += new DoWorkEventHandler(
        delegate(object o, DoWorkEventArgs args)
        {
            BackgroundWorker b = o as BackgroundWorker;

            this.Invoke(new MethodInvoker(delegate
            {
                getValues();//load some text fields into strings

                while (counter < counted)
                {
                    text = richTextBox1.Text;
                    text = text.Replace("number", finalNumber);

                    //create copies
                    if (checkBox1.Checked == true)
                    {
                        while (createdCopies < copies)
                        {
                            createdCopies++;

                            File.WriteAllText(fileName, text);
                            overalCounter++;
                            b.ReportProgress(overalCounter);
                        }
                        counter++;
                        createdCopies = 0;
                    }
                    //dont create copies
                    else
                    {
                        File.WriteAllText(fileName, text);
                        counter++;
                        overalCounter++;
                        b.ReportProgress(overalCounter);
                    }
                    //info about number of files created
                    label6.Text = "created " + overalCounter.ToString() + " files";

                }
                label1.Text = "success";
            }));
    });

    if (bw.IsBusy != true)
    {
        bw.RunWorkerAsync();
    }

    bw.ProgressChanged += new ProgressChangedEventHandler(
    delegate(object o, ProgressChangedEventArgs args)
    {
        this.Text = string.Format("{0}% Completed", args.ProgressPercentage);
    });
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:38:45+00:00Added an answer on June 4, 2026 at 2:38 am

    this.Invoke runs the code inside on the UI thread, blocking any UI updates.
    Since you run everything in the Invoke method everything will run on the UI thread.

    Create a separate Invoke around each place where you modify your UI controls and leave the heavy work outside the Invokes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create an app which has a default image as the background
i want to create a trial version app, but i couldn't find how to
i want to create VOIP based app for blackberry. after research, i found that
I want to create a desktop like app, but I'm kind of confused as
I want to create an app that shows text, plays sound (mp3 files) and
I am developing a MVC 3 Web app and I want to create something
I want to create a Web app which would allow the user to upload
I want to create an iPhone app which makes calls to a web service.
I want to create a PHP app that can send text messages ; There
I want to create a web app that will use wicket, hibernate and spring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.