C# Winform Visual Studio Application hangs with "Not Responding" after some hours of use and Windows pop-up appears closing application. This often occurs when initiating a remote desktop to the computer or bringing the application window to focus after minimising.
The application consumes full CPU when bringing to focus and gets progressively sluggish in this process.
The windows form is multithreaded GUI for controlling a device via RS232. It uses a textbox for a debug output several times a second. Writing to the textbox is done with an Asynchronous method.
void asyncAppendTextBox(TextBox tb, string str)
{
if (IsHandleCreated)
{
tb.BeginInvoke(
new Action(() =>
{
tb.AppendText(str + appLifetimeSW.ElapsedMilliseconds.ToString());
}
));
}
}