Check if code is called from Windows Forms Application
<p>I have a class library that is either called from a webservice, a service or a windows forms app. </p>

<p>For the windows forms application I want to show a yes / no messagebox for the webservice and the service I just want to assume yes.</p>

<p>I know I can refactor my code to use an abstraction layer, e.g.</p>

<pre><code>var provider = new MessageBoxProvider(); // Or other implementation
var result = provider.QueryResult(...);
</code></pre>

<p>but besides that: </p>

<p>Is there a better way to check if code is called from a windows application? Currently I am doing</p>

<pre><code>System.Windows.Forms.Application.OpenForms.Count &gt; 0
</code></pre>