M
Martin Schmid
I've got this simple method to process images.. .however, the Refresh
doesn't seem to work... also, since it is looping over potentially many
files, I'd like to be able to add a 'Stop' button to the form taht would
stop the looping...
Basically... I think I need to use a thread, but it has been a long time
since I have worked w/ threads... I'm thinking that the ProcessImage would
need to be run in a separate thread so the Form itself can stay active...
presently, once this loop starts, the form kinda takes a back seat... i.e.,
it doesn't repaint or refresh or anything.
Can anyone offer some advice? Would I want to run ProcessImage in a separate
thread? If so, how do I get the fiTemp info to that other thread?
Thanks,
MS
private void button1_Click(object sender, System.EventArgs e)
{
lblStatus.Text="Working...";
DirectoryInfo di = new DirectoryInfo(textBox1.Text);
FileInfo[] fi = di.GetFiles();
foreach (FileInfo fiTemp in fi)
{
if (fiTemp.Name.ToLower().EndsWith(".jpg"))
{
richTextBox1.Text=richTextBox1.Text+fiTemp.FullName+"\r";
this.Refresh;
ProcessImage(fiTemp);
}
}
lblStatus.Text="Done!";
}
doesn't seem to work... also, since it is looping over potentially many
files, I'd like to be able to add a 'Stop' button to the form taht would
stop the looping...
Basically... I think I need to use a thread, but it has been a long time
since I have worked w/ threads... I'm thinking that the ProcessImage would
need to be run in a separate thread so the Form itself can stay active...
presently, once this loop starts, the form kinda takes a back seat... i.e.,
it doesn't repaint or refresh or anything.
Can anyone offer some advice? Would I want to run ProcessImage in a separate
thread? If so, how do I get the fiTemp info to that other thread?
Thanks,
MS
private void button1_Click(object sender, System.EventArgs e)
{
lblStatus.Text="Working...";
DirectoryInfo di = new DirectoryInfo(textBox1.Text);
FileInfo[] fi = di.GetFiles();
foreach (FileInfo fiTemp in fi)
{
if (fiTemp.Name.ToLower().EndsWith(".jpg"))
{
richTextBox1.Text=richTextBox1.Text+fiTemp.FullName+"\r";
this.Refresh;
ProcessImage(fiTemp);
}
}
lblStatus.Text="Done!";
}