Yay I finally thought of a title!
I have a foreach loop that iterates the ListViewItems and does something with each item. But the problem is not that it doesn’t do the work in the loop, but it simply does not execute any code that appears before the foreach loop.
Below is the full method:
private void pNGToolStripMenuItem_Click(object sender, EventArgs e)
{
stat.Text = "Converting to PNG.";
_piclist.Enabled = false;
foreach (ListViewItem item in _piclist.Items)
{
try
{
/* magical image conversion here. */
_piclist.Enabled = true;
stat.Text =
"Conversion complete.";
}
catch (Exception exception)
{
stat.Text =
exception.Message;
}
}
}
Can somebody please help me understand why the code:
stat.Text = "Converting to PNG.";
_piclist.Enabled = false;
before the foreach loop never gets executed?
Thanks
It does. The thing is that body of your loop immediately overwrites the results of code that was run before:
You don’t see it, because UI freezes while your method execute and you see only last changes. Consider using threads, great article here: http://msdn.microsoft.com/en-us/magazine/cc164037.aspx