I have a label in a WinForm.in the app, I create a thread for setting the Text property of the label. since the code responsible for setting the Text property of the label is another thread, I wrote it like this :
private void SetLabel8Text(string text)
{
try
{
if (this.label8.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetLabel8Text);
this.Invoke(d, new object[] { text });
}
else
{
this.label8.Text = text;
}
}
catch (Exception ex)
{
}
}
now, I also handle the KeyPress event like so :
if (e.KeyChar.ToString() == "\r")
{
SetLabel8Text("Enter key Pressed !");
}
the problem I'm facing is that after pressing the Enter Key (execution of the KeyPress event), the SetLabel8Text method never gets executed.
everything else seems to flow nicely , I tried stepping through the code and it hangs at this place(inside the SetLabe8Text method :
this.Invoke(d, new object[] { text });
it hangs and doesn't move forward a bit.