我在Thread中的API方法中使用数组时遇到问题 锁定阵列不起作用。
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异常称为DISP_E_ARRAYISLOCKED。
答案 0 :(得分:0)
我现在正在使用AddReferences方法,我不再获得Exception了。
以下是更新后的代码:
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);
}