Thread Pooling for a method which has a return type
<p>I have a method named <code>InitializeCRMService()</code> which returns an object of <code>IOrganizationService</code>. Now I am defining a different method named <code>GetConnection(string thread)</code> which calls <code>InitializeCRMService()</code> based on the parameter passed to it. If the string passed to <code>GetConnection</code> is single it will start a single threaded instance of the <code>IntializeCRMService()</code> method, but if the string passed is multiple, I need to use a thread pool where I need to pass the method to <code>QueueUserWorkItem</code>. The method <code>InitializeCRMService</code> has no input parameters. It just returns a service object. Please find below the code block in the <code>GetConnection</code> method:</p>

<pre><code>public void GetConnection(string thread)
{
    ParallelOptions ops = new ParallelOptions();

    if(thread.Equals("one"))
    {
        Parallel.For(0, 1, i =&gt;
        {
            dynamic serviceObject = InitializeCRMService();       
        });
    }
    else if (thread.Equals("multi"))
    {
        // HERE I NEED TO IMPLEMENT MULTITHREADING USING THREAD POOL 
        // AND NOT PARALLEL FOR LOOP......
        // ThreadPool.QueueUserWorkItem(new WaitCallback(InitializeCRMService));
    }
}
</code></pre>

<p>Please note my method <code>InitializeCRMService()</code> has a return type of Service Object.</p>

<p>Please tell me how do I implement it.</p>
