0

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.

asked Sep 29, 2017 at 9:22
3
  • 2
    A 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. Commented Sep 29, 2017 at 9:27
  • 1
    The error basically indicates that running this code on a worker thread was not a good idea. You'll have to ask SolidWorks what it is possible, but the expected response is "don't do that". Commented Sep 29, 2017 at 9:30
  • Within the implementation of IEdmAddCustomRefs2 there is an safe array where the calls to SafeArrayLock exceed the calls to SafeArrayUnlock Commented Sep 29, 2017 at 9:33

1 Answer 1

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);
}
answered Sep 29, 2017 at 9:49

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.