CustomXMLParts.Add slow due to ContextSwitchDeadlock
<p>I'm getting a </p>

<blockquote>
  <p>ContextSwitchDeadlock</p>
</blockquote>

<p>when adding a <code>CustomXMLPart</code> after performing a <code>Documents.Add()</code>.</p>

<p>The same code was working fine last week..</p>

<p>I understand that ContextSwitchDeadlock is caused by a long running operation (this is not a duplicate question).
Why would the CustomXMLParts.Add() command result in a long running operation?</p>

<p>Anyone come across this? and any ideas how to troubleshoot?</p>

<blockquote>
  <p>ContextSwitchDeadlock occurred Message: Managed Debugging Assistant
  'ContextSwitchDeadlock' has detected a problem in 'C:\Program Files
  (x86)\Microsoft Office\root\Office16\WINWORD.EXE'. Additional
  information: The CLR has been unable to transition from COM context
  0xfdb520 to COM context 0xfdb468 for 60 seconds. The thread that owns
  the destination context/apartment is most likely either doing a non
  pumping wait or processing a very long running operation without
  pumping Windows messages. This situation generally has a negative
  performance impact and may even lead to the application becoming non
  responsive or memory usage accumulating continually over time. To
  avoid this problem, all single threaded apartment (STA) threads should
  use pumping wait primitives (such as CoWaitForMultipleHandles) and
  routinely pump messages during long running operations.</p>
</blockquote>