Hi,
I have another question,
I try to make my threads updating the form,
it works fine, for the first thread ,
but afterwards its not updating the labels on the form anymore
not from inside the thread and not outside,
tried to use refresh() and DoEvents() , nothing worked out, is this function SetText lock the control or something ?
the code I use to do it , is a code I found on this site,
this is what it looks like:
delegate void SetTextCallback(string text);
private void SetText(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.label6.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.label6.Text = text;
}
}
public string Scan(string stat)
{
if (stat == "1")
{
//during this thread run labels are updated fine.
z = new Thread(delegate() { FileSearch("*.exe"); });
//Start the thread
z.Start();
}
if (stat == "2")
{
//at this point the labels are not updated anymore on the GUI,
// not in threads and not outside them.
label6.Text="testetstestsetsetse";
SetText("testing...........................");
Application.DoEvents();
//at the messagebox it is showing the new text and on the form it doesnt.
MessageBox.Show(label6.Text);
z = new Thread(delegate() { FileSearch("*.com"); });
z.Start();
}