Thread is not running?

May 27 2008 6:38 AM

Hi,

 I am developing a system with c#.net. I have a simple application that create an excel book and write data which were retrieved from sql data base and save in hard disk. I want to show the prgress of data writing using a label. I use a thread function to display the progress with a lalbel. when i click the button, the thread is running but it the value is not shown in the label. but when the excel book creting function is completed then a value is displayed in the lebel. wht is wrong ?

here is the thread function...

private void DataProgress()

{

int value = 0;

while (true)

{

value++;

SetControlPropertyValue(label1, "Text", value.ToString());

Thread.Sleep(100);

}

}// end

 

private void btnStart_Click(object sender, EventArgs e)

{

Thread trd = new Thread(new ThreadStart(this.DataProgress));

trd.IsBackground = true;

trd.Start();

 

GenerateReport();

trd.Suspend();

MessageBox.Show("end");

}

delegate void SetControlValueCallback(Control oControl, string propName, object propValue); //Leo Delegate

private void SetControlPropertyValue(Control oControl, string propName, object propValue)

{

if (oControl.InvokeRequired)

{

SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);

oControl.Invoke(d, new object[] { oControl, propName, propValue });

}

else

{

Type t = oControl.GetType();

System.Reflection.PropertyInfo[] props = t.GetProperties();

foreach (System.Reflection.PropertyInfo p in props)

{

if (p.Name.ToUpper() == propName.ToUpper())

{

p.SetValue(oControl, propValue, null);

}

}

}

}


Answers (1)