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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:00:35+00:00 2026-05-16T09:00:35+00:00

I made a program in wpf c#. I made a drag and drop handler

  • 0

I made a program in wpf c#.
I made a drag and drop handler which adds some items to a listbox. While the program is doing that (it takes some time) I want a Grid to change its property visiblity to visible and I want to update a textbox to show the user which file is being processed. The code is as follows:

UPDATE: Solution implementation Try

            BackgroundWorker bgWorker = new BackgroundWorker(); 
private void Dropaudio(object sender, System.Windows.DragEventArgs e) 
{ 


    bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork); 
    bgWorker.ProgressChanged +=  
        new ProgressChangedEventHandler(bgWorker_ProgressChanged); 
    bgWorker.WorkerReportsProgress = true; 
    this.Drop += new DragEventHandler(Dropaudio);
    if (e.Data.GetDataPresent(DataFormats.FileDrop)) 
    { 
        string[] droppedFilePaths =  
            e.Data.GetData(DataFormats.FileDrop, true) as string[]; 
        List<string> Jobs = new List<string>(droppedFilePaths); 
        bgWorker.RunWorkerAsync(Jobs); 
    } 
} 

void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) 
{ 
    if (e.ProgressPercentage == 0) 
    { 
        Addingcues.Visibility = Visibility.Visible; 
    } 
    addcuepath.Text = e.UserState.ToString(); 
} 

void bgWorker_DoWork(object sender, DoWorkEventArgs e) 
{ 
    List<string> Jobs = e.Argument as List<string>; 
    bgWorker.ReportProgress(0, "Processing Data"); 
    double count = 0; 
    double total = Jobs.Length; 
    foreach (string droppedFilePath in Jobs) 
    {                 
        if (System.IO.Path.GetExtension(droppedFilePath) == ".mp3" ||  
            System.IO.Path.GetExtension(droppedFilePath) == ".wav" ||  
            System.IO.Path.GetExtension(droppedFilePath) == ".flac") 
        { 
            double pct = count / total; 
            // Report this file 
            bgWorker.ReportProgress((int) (pct * 100), droppedFilePath); 
            var provider = (XmlDataProvider)this.Resources["CUEData"]; 
            XmlDocument xmlcuelijst = provider.Document;
            XmlNode cueshow = xmlcuelijst.SelectSingleNode("CUEShow");
            XmlNode maincues = cueshow.SelectSingleNode("Maincues");
            XmlElement Maincue = xmlcuelijst.CreateElement("Maincue");
            XmlElement nr = xmlcuelijst.CreateElement("nr");
            XmlElement Description = xmlcuelijst.CreateElement("Description");
            XmlElement Cuetype = xmlcuelijst.CreateElement("Cuetype");
            XmlElement Name = xmlcuelijst.CreateElement("Name");
            XmlElement Path = xmlcuelijst.CreateElement("Path");
            XmlElement Duration = xmlcuelijst.CreateElement("Duration");
            XmlElement Type = xmlcuelijst.CreateElement("Type");
            XmlElement Fade = xmlcuelijst.CreateElement("Fade");
            XmlElement Fadein = xmlcuelijst.CreateElement("Fadein");
            XmlElement Fadeout = xmlcuelijst.CreateElement("Fadeout");
            XmlElement Delay = xmlcuelijst.CreateElement("Delay");
            XmlElement Delaytime = xmlcuelijst.CreateElement("Delaytime");
            XmlElement Loop = xmlcuelijst.CreateElement("Loop");
            XmlElement FX = xmlcuelijst.CreateElement("FX");
            XmlElement Filename = xmlcuelijst.CreateElement("Filename");
            Maincue.AppendChild(nr);
            Maincue.AppendChild(Cuetype);
            Maincue.AppendChild(Name);
            Maincue.AppendChild(Path);
            Maincue.AppendChild(Description);
            Maincue.AppendChild(Duration);
            Maincue.AppendChild(Type);
            Maincue.AppendChild(Fade);
            Maincue.AppendChild(Fadein);
            Maincue.AppendChild(Fadeout);
            Maincue.AppendChild(Delay);
            Maincue.AppendChild(Delaytime);
            Maincue.AppendChild(Loop);
            Maincue.AppendChild(FX);

            count += 1; 
        } 
    } 

} 

void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 
{ 
    Addingcues.Visibility = Visibility.Hidden; 
}

This works (changed array to a list) but at the Appendchild actions, the code just suddenly stops running, I set two breakpoints at the first and second Appendchild line and the first is triggered but the second isn’t…

  • 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-16T09:00:36+00:00Added an answer on May 16, 2026 at 9:00 am

    It is difficult to tell exactly what makes this code need Invoke/BeginInvoke – it looks like the Dropaudio method is just an event handler (on the GUI thread).

    Perhaps the easiest thing to do is to use a BackgroundWorker, which is designed to make simple multi-threading easier.

    class MyClass
    {
        BackgroundWorker bgWorker = new BackgroundWorker();
    
        public MyClass()
        {
            bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
            bgWorker.ProgressChanged += 
                new ProgressChangedEventHandler(bgWorker_ProgressChanged);
            bgWorker.WorkerReportsProgress = true;
            this.Drop += new DragEventHandler(Dropaudio);
        }
    
        private void Dropaudio(object sender, System.Windows.DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] droppedFilePaths = 
                    e.Data.GetData(DataFormats.FileDrop, true) as string[];
                List<string> Jobs = new List<string>(droppedFilePaths);
                bgWorker.RunWorkerAsync(Jobs);
            }
        }
    
        void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (e.ProgressPercentage == 0)
            {
                Addingcues.Visibility = Visibility.Visible;
            }
            addcuepath.Text = e.UserState.ToString;
        }
    
        void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string[] Jobs = e.Argument as string[];
            bgWorker.ReportProgress(0, "Processing Data");
            double count = 0;
            double total = Jobs.Count;
            foreach (string droppedFilePath in Jobs)
            {                
                if (System.IO.Path.GetExtension(droppedFilePath) == ".mp3" || 
                    System.IO.Path.GetExtension(droppedFilePath) == ".wav" || 
                    System.IO.Path.GetExtension(droppedFilePath) == ".flac")
                {
                    double pct = count / total;
                    // Report this file
                    bgWorker.ReportProgress((int) (pct * 100), droppedFilePath);
                    var provider = (XmlDataProvider)this.Resources["CUEData"];
                    XmlDocument xmlcuelijst = provider.Document;
                    // Do other stuff from above
                    count += 1;
                }
            }
    
        }
    
        void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            Addingcues.Visibility = Visibility.Hidden;
        }       
    }
    

    Note that you could easily add a ProgressBar when using the ProgressChanged event. I’m assuming that “Addingcues” is the control you want visible during the processing, and “addcuePath” is the textbox (TextBlock?) that you want updated with the progress.

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

Sidebar

Related Questions

I made a program which i want to launch with some protocal for eg
So I made a program that uses four differrent processes to do some stuff.
I made a program in Xcode, being a simple calculator that takes a first
I made a program to perform some astronomical calculations. It takes only 6 parameters:
I made a program that is an onscreen keyboard. The program has some keys
I made a WPF/C# program and I am using the internet control for WYSIWYG
I made a program in Idle that says: for trial in range(3): if input('Password:')
I made a program that opens an application, sleeps the thread for 500ms then
I made a program that returns the sum of all primes under 2 million.
I made a program that returns the product a b c where a,b,c are

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.