How to saveElement in EVENT_AFTER_SAVE_ELEMENT without infinite loop
I got this working by using the EVENT_BEFORE_SAVE_ELEMENT and adding the asset to the entry asset field 'pdfThumbnailImage' by using the setFieldValue.

 $entry-&gt;setFieldValue('pdfThumbnailImage', [$assetId]);


You dont need to save the element - leave this out

 Craft::$app-&gt;elements-&gt;saveElement($element); // causes loop