1

I have a Winforms application, that is deployed on many client sites, and runs with no problems.

I have one site (actually a second has just reported it), where the application will just freeze for no reason.

Event single stack trace we get via a mini dump shows the freeze in the OnUserChanged event...

enter image description here

The ViewManager.RunApplication is where I call Application.Run(m_mainFrame.Form); where m_mainForm is my main application Form.

I have found many many posts on this and various suggestions, for example custom splash screen - I removed this - no difference, subscribe to the Microsoft.Win32.SystemEvents* events near app startup as shown below

    [STAThread]
    static void Main(string[] args)
    {      
      AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

      Thread.CurrentThread.Name = "My App";

      // Empty handler to try and stop freeze
      Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
      Microsoft.Win32.SystemEvents.DisplaySettingsChanging += SystemEvents_DisplaySettingsChanging;
      Microsoft.Win32.SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;

      // Must be called before first window creation:
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);

I tried to follow this post on one of the memory dumps I have been given, but could not get past the second step with windbg

I gave up on this, and next followed what was suggested here

I was given access to a problem client machine, and when it froze, used spy++ to get the following results...

enter image description here

As suggested in the post, I expanded the threads and looked for a second thread

I can see two threads with windows in there. Looking into a memory dump I did at the same time, so I could match up the thread Ids), both these threads were just unnamed worker threads (I could not see the main UI thread there wit a window)

The one with TabletPenServiceHelperClass looks unusual, and I cannot find much information on it.

Does any one have any suggestions on where to go from here, or what the TabletPenServiceHelperClass is, and could this have anything to do with these freezing? This is such a frustrating problem.

Thanks in advance for any information

[UPDATE1]

It looks like the thread IDs in Spyxx and Visual Studio (debugging) don't match up at all. I ran my app on my local machine (so I could see what Windows I have inb spyxx), and I can identify my main UI thread in both places, and they have completely different ids...

enter image description here

At any rate, I can see in spy++, I have my main app UI thread with a window, and two extra windows under one other thread...

enter image description here

I am not sure what this one is either. When I go into the properties (via spy++) I can see one of these windows has the caption .NET-BroadcastEventWindow.4.0.0.0.3f2ddb3.0, the other just says Default IME.

Does anyone know what these are (Googling does not bring up much.. yet)

At any rate, I don't have the TabletPenServiceHelperClass as the troublesome instance has.

peterc
  • 6,921
  • 9
  • 65
  • 131
  • Have you searched for `Wisptis.exe` (\System32, usually)?. Part of the `Windows ink Services`. Can be executed on startup or in combination with some well know programs (Adobe Reader, for example). With `TabletPenServiceHelperClass` can be part of the Windows OOBE (`HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OOBE`) See: [Customize the Out of Box Experience (OOBE)](https://learn.microsoft.com/en-us/windows-hardware/customize/desktop/customize-oobe). Remove the .exe and retry. – Jimi Aug 03 '18 at 08:42

2 Answers2

0

SystemEvent.OnUserPreferencesChanged freeze usually could be reproduced by just locking (Win+L) and than unlocking Windows screen.

Please try to call CheckSystemEventsHandlersForFreeze() method from this answer (before or even after freeze!) to find out which particulat controls was initially created on a wrong (non-UI, usually thread pool) thread and thus causing freeze.

Vlad Rudenko
  • 2,363
  • 1
  • 24
  • 24
0

I finally found the problem in my case. I had to use MS support, and using a dump file, they were able to pin point where I had a windows that WAS created on a worker thread. Looking at the code, my guess was that I had an InvokeRequired failing as it was called before the control it was called on had a window handle.

I now ALWAYS call InvokeRequired on the main application window, but there was one nested very deep that was missed.

If you have the case as here, ie a window created on a worker thread, a OnUserPreferencesChanged can later cause this freeze.

peterc
  • 6,921
  • 9
  • 65
  • 131