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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:21:00+00:00 2026-05-11T22:21:00+00:00

I have a listbox in which i have to give minimum 2 files for

  • 0

I have a listbox in which i have to give minimum 2 files for merging.
the merging is done when i click Merge button.The progress bar starts and the message box appears That the files has been merged.i am using background worker to run the progress bar.

Now the problem is when the merging is done with 2 files,i add one more file,Click the merge button merging is done message appears i click OK on the message box,again the message box appears with same message that merging has been done.This message box continues appearing the number of times i add the file in the listbox .

For example, for 2 files message appears 1ce den on adding 1 more file message appears 2ice ,1 more file in listbox message appears 3ic.Like dis it continues….

When i used the debugger to track it, i noticed that my Background Worker Runcompleted event is called that number of times whenever i add file in the listbox.Here is the code for Merge button Click event…

Worker.DoWork += new DoWorkEventHandler(Worker_DoWork);
Worker.RunWorkerCompleted +=
    new  RunWorkerCompletedEventHandler(Worker_RunWorkerCompleted);
Worker.WorkerSupportsCancellation = true;

if (!Worker.IsBusy)
    Worker.RunWorkerAsync();
else
    MessageBox.Show("Cannot run background worker twice ");

if (Worker.IsBusy)
{
    progress = new ProgressDialogDTB();
    progress.FormClosing += 
        new FormClosingEventHandler(ProgressDialog_FormClosing);
    progress.ShowDialog(this);
}
while (Worker.IsBusy)
{
    Application.DoEvents();
}

//For Background Worker completed Event...
private void Worker_RunWorkerCompleted(object sender, 
    AsyncCompletedEventArgs e)
{            
    if (progress != null)
    {
        progress.Close();
        progress = null;
    }
    if ( e.Cancelled )
        MessageBox.Show(" Progress was cancelled ");                               

    if (e.Error == null)
        if (!e.Cancelled)
            MessageBox.Show("Files has been merged ");

    if (e.Error != null)
        MessageBox.Show(e.Error.Message);     
}//Worker_RunWorkerCompleted

I don’t know where i am getting wrong.
Please help…Thanks…

  • 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-05-11T22:21:01+00:00Added an answer on May 11, 2026 at 10:21 pm

    I’m guessing that on each Merge button click you are registering a new delegate. If the following code:

    Worker.DoWork += new System.ComponentModel.DoWorkEventHandler(Worker_DoWork);
    Worker.RunWorkerCompleted += new  System.ComponentModel.RunWorkerCompletedEventHandler(Worker_RunWorkerCompleted);
    

    is in the click event handler of the Merge button consider moving it to your form initailization method. You only need to register a delegate once. Next time you do it adds a new one so on second Merge click it will run twice, on third click three times and so on.

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

Sidebar

Related Questions

I have a listbox which acts as a list of items. If you click
[Original] I have a ListBox which has its ItemsSource (this is done in the
I have a Listbox which contain a list of files . can i access
I have a ListBox which displays items of variable height. I want to show
I have WPF ListBox which is bound to a ObservableCollection, when the collection changes,
I have this ListBox which is bound to an ObservableCollection. Each object in the
I have a ListBox which is populated from a collection of ViewModels, which uses
I have a ListBox which uses a DataTemplate to render databound items. The XAML
So, I have a ListBox which is bound to a list of business objects,
I have a WPF listbox which displays messages. It contains an avatar on the

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.