0

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()); } )); } }

Spiffalski
  • 58
  • 2
  • 5

1 Answers1

0

The answer to this problem was fairly simple in the end. The Textbox was simply getting too full of text and eventually taking >minutes to repaint everything when bringing back to focus. This eluded me at first because the textbox was painting no problem with the AppendText() function. After some hours of the program running, the amount of text was effectively appearing to hang the application (according to Windows).

The simple fix was to write to a string array instead and set the text in the text box via 'Textbox.SetText(string[])' in the asynchronous invoke method. I additionally shift the array by one and write to the last element of the array to match the appearance of AppendText().

No more hanging and application is responsive.

Spiffalski
  • 58
  • 2
  • 5