Winforms UI Freeze - OnUserPreferenceChanged

James Carmen 6 Reputation points
2022-05-17T02:37:41.553+00:00

Hi,

I have an winforms application (running on .net 4) in a production environment that over the last 2 months has been sporadically experiencing a UI freezing issue, whereby the application will enter a waiting state (locking the UI), however windows does not treat this as a hanging application, as repeated attempted interaction with the form will not prompt the "application may be frozen form" windows typically suggests when detecting a frozen/hanging application.

We haven't been able to reproduce this in any lab, and due to the nature of the clients environment, haven't had much exposure to the live issue when it has occurred, making troubleshooting quite difficult, however one occasion i did manage to get a mini dump of the state of the application in its frozen state:

202571-trace.png

As you can see, it looks like the OnUserPreferenceChange system event was raised, followed by the thread waiting, presumably locking the ui?
Doing some research online, it looks like this is a fairly commonly seen issue (at least a few years ago), with a few suggestions surrounding ensuring background threads do not open forms, and specifically referencing the handle of a new form to force its creation, however in this case, we aren't sure exactly where this issue may be originating due to the size and complexity of our application, and any attempt to reproduce what we have seen in our logs, hasn't worked.

Online references:
https://localcoder.org/windows-form-application-freeze-randomly-when-run-overnight
https://www.ikriv.com/dev/dotnet/MysteriousHang
https://stackoverflow.com/questions/10436981/winforms-application-hang-due-to-systemevents-onuserpreferencechanged-event/52721562#52721562

Further to this, we have seen this issue appear 2 months ago in 2 different environments without any changes to our application around that time, so with that in mind my questions would be:

  1. What suggestions do you have in order to further narrow down/prevent this issue?
  2. Is this something that has been seen in some versions of .net that has been previously fixed?
  3. What would cause this issue to suddenly occur (thinking a windows setting change that fires this event?)
  4. Would one way to handle this (as suggested in the link above) but to simply subscribe to these events, or would this cause other unknown issues?

Understand this isn't a lot to go on without a section of code to analyse, however as mentioned above, if we knew exactly where this issue originated from we could probably fix it ourselves.
Happy to provide as much information to help as needed.

Thanks in advance!

PS. Apologies for tagging this azure-asia, but it was suggested to us to do so to try illicit a fast response

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,836 questions
Azure FastTrack
Azure FastTrack
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.FastTrack: This tag is no longer in use. Please use 'Azure Startups' instead.
75 questions
{count} votes