Is it allowed/discouraged to use a Label in a Windows Form application for displaying the application status?
At first I thought it would have been a wise idea, but now I realized I have many logs that do not display, and often crashes if I don’t put a try/catch around the Label.Text change.
Here’s the function I use.
private void Echo(string p)
{
lock (m_syncObject)
{
try
{
InfoBox.Text = p.ToString();
}
catch { }
}
}
As you can see, I also added a lock to multiple access to the same resource.
Can anyone explain why do I frequently end up in the ‘catch’?
InfoBox.Text = p.ToString(); -> That can generate a cross-thread exception. Try this instead: