.NET 4.0 and the dreaded OnUserPreferenceChanged Hang

后端 未结 3 2155
庸人自扰
庸人自扰 2020-11-27 07:02

I have been plagued with the dreaded OnUserPreferenceChanged Hang that\'s refered to quite nicely by Ivan Krivyakov, here:

http://ikriv.com/en/prog/info/dotnet/Myste

3条回答
  •  [愿得一人]
    2020-11-27 07:28

    The best guide I've found for resolving this issue is here:

    • Debugging Windows Forms Application Hangs During SystemEvents.UserPreferenceChanged - The DSUI Team Blog - Site Home - MSDN Blogs

    It walks you through using WinDbg to verify the cause of the error and shows you how to find what's causing it. As you mentioned it is most likely caused be a control being created on a non ui thread.

    In my case I resolved the issue by creating a factory that uses the SynchronizationContext from the UI thread to create the control and then I call CreateControl() in order to force the creation of a UI handle.

    The Microsoft Support article is here:

    • Windows Forms application freezes when system settings are changed or the workstation is locked

提交回复
热议问题