title: Is it safe to use different AdhocWorkspace instances concurrently?
body: <p>I am facing a case where I would like to use <strong>different instances</strong> (<em>not</em> one shared instance) of <code>Microsoft.CodeAnalysis.AdhocWorkspace</code> (<a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.adhocworkspace" rel="nofollow noreferrer">docs</a>) concurrently in multiple threads (=&gt; one seperate instance per thread).</p>
  <p>One thing which struck me, while looking at the default-constructor of the <code>AdhocWorkspace</code>, was that it's always using a static <code>MefHostServices</code> instance behind the scenes:</p>
  <pre class="lang-cs prettyprint-override"><code>public AdhocWorkspace() : this(Host.Mef.MefHostServices.DefaultHost)
  </code></pre>
  <p>This made me curious, and I did a bit of research, to find out whether several concurrent <code>AdhocWorkspace</code>s could cause any problems.</p>
  <p><strong>Results:</strong></p>
  <ul>
  <li>I couldn't find any documentation which is either explicitly stating that it's safe or not.</li>
  <li>I found a few old github issues like <a href="https://github.com/dotnet/roslyn/issues/16124" rel="nofollow noreferrer">this</a> and <a href="https://github.com/dotnet/roslyn/issues/16184" rel="nofollow noreferrer">this</a>, which are discussing concurrency problems. Especially the latter one, sounds like it's ok as long as we use just one host service (which seems to be the case with the default constructor), although I'm not sure if this is even relevant for my case.</li>
  <li>I actually tried out to use a lot of <code>AdhocWorkspace</code>s in parallel (adding documents, projects and compiling) and did not experience any problems so far.</li>
  </ul>
  <p><strong>Conclusion:</strong> Although it looks good so far I would be interested in <em>how this was actually designed to work</em>. Especially in case of possible race-conditions I would not like to rely on a quick test and a bit of research without a clear result.</p>
  <p>Maybe someone can point me to a relevant piece of documentation or code? Or even a roslyn team member can bring some clarification?</p>
  <p><em>Note: I am not really familiar with MEF, so maybe it would be easier for me to answer this question myself, if I had the lacking MEF knowledge.</em></p>