I've got a problem with using arrays in an API method in a Thread.
Locking the arrays didn't work.
Thread thrCreate = new Thread(createThread);
thrCreate.SetApartmentState(ApartmentState.STA);
thrCreate.Start();
private void createThread()
{
IEdmAddCustomRefs2 pdmRefs = (IEdmAddCustomRefs2)vault2.CreateUtility(EdmUtility.EdmUtil_AddCustomRefs);
IEdmFile5 pdmRefFile = (IEdmFile5)pdmResult;
int[] iRefCount = new int[1];
iRefCount[0] = 1;
string[] strRefPath = new string[1];
strRefPath[0] = strPDFPath + strSerName + ".pdf";
lock (strRefPath)
{
lock (iRefCount)
{
pdmRefs.AddReferencesPath2(pdmRefFile.ID, ref strRefPath, ref iRefCount);
}
}
}
COM Exception is called DISP_E_ARRAYISLOCKED.
Anton L.Anton L.
1 Answer 1
I am now using the AddReferences method and I am not getting the Exception anymore.
Here is the updated code:
Thread thrCreate = new Thread(createThread);
thrCreate.SetApartmentState(ApartmentState.STA);
thrCreate.Start();
private void createThread()
{
IEdmAddCustomRefs2 pdmRefs = (IEdmAddCustomRefs2)vault2.CreateUtility(EdmUtility.EdmUtil_AddCustomRefs);
IEdmFile5 pdmRefFile = (IEdmFile5)pdmResult;
string[] strRefPath = new string[1];
strRefPath[0] = strPDFPath + strSerName + ".pdf";
pdmRefs.AddReferencesPath(pdmRefFile.ID, ref strRefPath);
}
Comments
Explore related questions
See similar questions with these tags.
lang-cs
lock
statement will not help here. The lock being referred to in the HRESULT's name is the locking of the COM array contained in a Variant.IEdmAddCustomRefs2
there is an safe array where the calls toSafeArrayLock
exceed the calls toSafeArrayUnlock