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 8897757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:25:48+00:00 2026-06-15T00:25:48+00:00

When I press btn_Connect the backgroundworker will but when it reaches it prompting the

  • 0

When I press btn_Connect the backgroundworker will but when it reaches it prompting the messagebox after i click ok on messagebox it will run again and display messagebox again and when I click btn_Connect again it will do the same and it will increment so the first click is twice the second click of the btn_Connect will display the messagebox thrice. How to fix this,

Here is my code:

private void testConnection()
    {
        backgroundWorker.ReportProgress(15);

        txt.createConnectionFile(txtServerName.Text, txtDatabase.Text, txtUserName.Text, txtPassword.Text);

        backgroundWorker.ReportProgress(30);

        cn.createConnection();

        backgroundWorker.ReportProgress(60);

        try
        {
            backgroundWorker.ReportProgress(80);

            cn.openConnection();

            MessageBox.Show("Connected!", "Connection Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

        backgroundWorker.ReportProgress(100);
    }

    private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        progressBar.Value = e.ProgressPercentage;
    }

    private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        testConnection();
    }
private void btnConnect_Click(object sender, EventArgs e)
    {
        progressBar.Visible = true;
        backgroundWorker.WorkerReportsProgress = true;
        backgroundWorker.WorkerSupportsCancellation = true;
        backgroundWorker.ProgressChanged += backgroundWorker_ProgressChanged;
        backgroundWorker.DoWork += backgroundWorker_DoWork;

        backgroundWorker.RunWorkerAsync();
    }
  • 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-15T00:25:49+00:00Added an answer on June 15, 2026 at 12:25 am

    One thing I notice is that you keep wiring up the DoWork and RunWorkerCompleted events every time the button is clicked.

    Based on the code above, I suspect that the first time you click the button it runs once, then the button becomes enabled again. The next time you click the button, it will run twice, next time three times, etc.

    You need to wire up the events outside of the button click. In the OnLoad for instance.

    If you can’t do that replace the click code with

    private void btnConnect_Click(object sender, EventArgs e)
        {
            progressBar.Visible = true;
            backgroundWorker.WorkerReportsProgress = true;
            backgroundWorker.WorkerSupportsCancellation = true;
            backgroundWorker.ProgressChanged -= backgroundWorker_ProgressChanged;
            backgroundWorker.ProgressChanged += backgroundWorker_ProgressChanged;
    
            backgroundWorker.DoWork -= backgroundWorker_DoWork;
            backgroundWorker.DoWork += backgroundWorker_DoWork;
    
            backgroundWorker.RunWorkerAsync();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't press any other buttons in the same window while UIScrollView is zooming
When I press F5, everything compiles fine, but when the app is to be
I'm attempting to switch scenes with the storyboard, but when I press the button,
i have this two button.as i press the first it plays an mp3 file.but
What I planned to do is when I press Enter key, the application will
I want to implement a long press on my button and after that long
Ok, I dunno why is this happening but when I press close button, the
I press login button to login into my app and I'm using asyncTask for
When I tried press the CTRL+D+E keys combination, I typed a wrong combination that
When I press CTRL + Space the auto completing not working. It doesn't show

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.