In my Word Addin I need to store relations between keys, values and content control ids. Currently I store these relations in document.properties.customProperties. I use the key as the customProperty key and add the value and ids as stringified JSON to load and reuse during future Addin usages. This is the storage code:
private updateCustomProperties(normalizedData: Array<{ [key: string]: string; }>): Promise<void> {
return Word.run(async (context) => {
normalizedData.forEach(async newProp => {
//create object with new value
let updateObj = { value: newProp.value };
//get content control ids. It is an array of numbers
let ids;
for (const listItem of this.linkListToCustomProperty) {
if (listItem.varName === newProp.key) {
ids = listItem.ccIds;
break;
}
if (typeof ids !== 'undefined') {
//add ids to update object
updateObj['ccIds'] = ids;
//set custom property to the update object
context.document.properties.customProperties.add(newProp.key, JSON.stringify(updateObj));
}
//sync
await context.sync();
}
});
context.document.properties.load('customProperties');
await context.sync();
});
}
The issue: After that storage process and the complete Addin process is finished, Word will completely block one core of CPU for up to half an hour and be pretty much unusable. If I try to use Word during that time, i.e. save the document or scroll/type, often Word will crash. I am assuming that storage in customProperties triggers some sort of endless garbage collection. I am storing up to 1000 keys with their values and ids.
I have tried different cycle sizes before context.synch() but did not see a change to the better. The size of custom properties is limited to 256 chars so I have to store each key in a separate property. Any ideas would be very welcome. Is there a better place to store this kind of data to reuse after closing/reopening the document? Is there a way to circumvent that high usage?