Julie said:
I have an application that uses an ActiveX control DLL. I just started
getting a LoaderLock error, but only when I debug and attempt to stop
at a breakpoint. If I don’t stop at the breakpoint, I don’t get the
error.
I believe this only started happening once I changed my code to add a
new thread, which handles the ActiveX control, along with the Windows
Form that it sits on. When I used to have this logic on the original
thread, I was able to set breakpoints with no problem.
Does this make any sense? What do I do?
Hard to say without seeing a concise-but-complete code example that
reliably demonstrates the problem.
As you may know, the "LoaderLock error" is a Managed Debug Assistant
exception, reporting a _possible_ error in which you've attempted to
execute something during the loading of a DLL that could be a problem
(mainly, which could in turn require another DLL to be loaded, creating
a deadlock condition).
Unfortunately, there are benign, false positives that can occur. So
without seeing the specific initialization code, it's hard to know for
sure what might be wrong, if anything.
Personally, I'd be more concerned about the use of an ActiveX control
created on a thread different from your main Form's thread, especially
if that ActiveX control is actually a child control of the Form.
Managing multiple GUI threads in a single process is tricky enough, and
mixing those threads in the same window could be especially problematic.
And of course, it's _possible_ that your mixing of two windows that have
different owner threads into the same control hierarchy has led to the
LoaderLock exception, through some problem in the ordering of
initialization of the controls. I don't know, and there's not really
any way to know without seeing the code.
But even if not, I think you should probably restructure your code so
that the GUI parts all happen on the same thread. Background tasks
started by those GUI parts can, of course, still occur on other threads;
you just need to make sure the code specific to the window is executed
on the main thread.
Pete