I have a WinForms control in which I determine the system password character using code like this:
TextBox textBox = new TextBox();
textBox.UseSystemPasswordChar = true;
char passwordChar = (char)iGNativeMethods.SendMessage(myTextBox.Handle, iGNativeMethods.EM_GETPASSWORDCHAR, IntPtr.Zero, IntPtr.Zero);
textBox.Dispose();
This code snippet is called in the control’s constructor. One of my customers reported an issue with this part of code after running heavy unit tests. The most common error message was “System.ComponentModel.Win32Exception: Error creating window handle.” and it is related to the CreateHandle() method.
As I understand, many tests running in parallel simply exhaust the available pool of API resources. Is there any other way to determine the system password character in a WinForms app in .NET to avoid this issue?