me.ShowDialog() and LoaderLock
I like to keep a good separation between forms and function in Windows applications I write. So to call a login form, I might call a public function on the login form like: Login.GetLogin(loginName, password).
GetLogin might look like this (VB.NET):
Public Function GetLogin(ByVal strLogin As String, ByVal strPassword As String) As Integer
txtLogin.Text = strLogin.Trim
txtPassword.Text = strPassword.Trim
Me.ShowDialog()
Return mintToken
End Function
In .NET 2.0 and Visual Studio 2005, this causes an exception to pop-up:
LoaderLock was detected
Message: Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.
This exception is thrown on the first keystroke of my login form.
This seems to be a common problem, and the solution is to shut off the LoaderLock MDA (Managed Debugging Assistant). This can be done in the menu Debug -> Exceptions -> Managed Debug Assistants and unchecking the LoaderLock option. I don’t like this solution, but it seems to work.
This Microsoft KB Article on LoaderLock contains some good information about this issue. One of the commenters stated they had the same problem with an application throwing this each time a key is pressed, but no one has replied with a reason why. My Visual Studio 2005 project contains a form originally designed in VS 2003. I don’t know if that has something to do with it or not.
Hat tip: chrisB. Also Simon’s Software Stuffp
3 Comments
- Gaco said:
- CoDE said:
- John said:
