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...