Windows Form application freeze randomly when run overnight

前端 未结 5 698
离开以前
离开以前 2021-01-04 18:09

I have a window form application, and it has multiple threads running that would invoke on the Main UI thread to update the UI. Occasionally on development machine, the app

5条回答
  •  萌比男神i
    2021-01-04 18:50

    I experienced this exact same issue about a year ago (application hang after some time without user interaction, with OnUserPreferenceChanging() in the call stack).

    The most likely cause is that you're using InvokeRequired/Invoke() on a control and not on the main form. This sometimes produces the wrong result if the control's handle hasn't been created yet.

    The solution is to always call InvokeRequired/Invoke() on the Main Window (which you can cast as an ISynchronizeInvoke if you don't want to introduce a dependency to your form class).

    You can find an excellent, very detailed description of the cause and solution here.

提交回复
热议问题