I have some code that runs within a multithreaded class.
Basically i create many threads which contain instance of this class.
Within this class i create an object to either a vb6 or .net dll using reflection, then i call a method within that object. The object that gets called can be different every time.
But for some reason even through i have multiple threads going when i get to the Activator.CreateInstance it is no longer multithreaded. Why is that? How do i fix it?
I want to catch the error returned and put it in a log.
If UCase(pRow("TypeVB6").ToString()) = "TRUE" Then
classType = Type.GetTypeFromProgID(ClasstoInstantiate, True)
Else
classType = Type.GetType(ClasstoInstantiate, True)
End If
Dim o As Object = Activator.CreateInstance(classType)
cError = classType.InvokeMember(MethodName, BindingFlags.InvokeMethod Or BindingFlags.Instance Or BindingFlags.Public, Nothing, o, New Object() {FilePath, VirtDir})
A couple of ideas for a solution:
1) Verify that the main entry point for your service is decorated with the MTAThread Attribute
2) Wrap the Activator.CreateInstance call (and possibly the following InvokeMember method) in a SyncLock statement.